简体   繁体   中英

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.

#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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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