简体   繁体   English

Tkinter create_window,居中对齐

[英]Tkinter create_window, justify to center

I have this piece of code and I want these buttons to be at center of line.我有这段代码,我希望这些按钮位于行的中心。 Unfortunately justify doesn't work and text.window_config(INSERT, align="center") gives me error like this: no embedded window at index "insert" I know there is problem with INSERT but I have no idea what else should I put there.不幸的是 justify 不起作用, text.window_config(INSERT, align="center")给了我这样的错误: no embedded window at index "insert"我知道 INSERT 有问题,但我不知道我还应该放什么那里。

#text.window_config(INSERT, align="center")
for page in range(number_of_pages):
    page = page+1
    button = Button(text, text=page)
    button.configure(command=lambda button=button: goTo(page))
    text.window_create(INSERT, window=button)

Adding the window at the insertion cursor causes the insertion cursor to move one to the right.在插入 cursor 处添加 window 会导致插入 cursor 向右移动一位。 To reference the newly created window you can use "insert-1c", meaning "insert cursor minus one character" since a window logically takes up one "character" of space.要引用新创建的 window,您可以使用“insert-1c”,意思是“插入 cursor 减去一个字符”,因为 window 在逻辑上占用一个“字符”空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM