Tkinter: Difference between revisions

 
(One intermediate revision by the same user not shown)
Line 415:
</syntaxhighlight>
 
= Display window in Center =
<syntaxhighlight lang="python">
import tkinter
 
def center(toplevel):
toplevel.update_idletasks()
w = toplevel.winfo_screenwidth()
h = toplevel.winfo_screenheight()
size = tuple(int(_) for _ in toplevel.geometry().split('+')[0].split('x'))
x = w/2 - size[0]/2
y = h/2 - size[1]/2
toplevel.geometry("%dx%d+%d+%d" % (size + (x, y)))
 
root = Tk()
 
win = Toplevel(root)
win.title("Centered!")
center(win)
 
root.mainloop()
</syntaxhighlight>
 
<br />