Tkinter: Difference between revisions
→Add widgets to Notebooks
Line 415:
</syntaxhighlight>
= Display window in Center =
<syntaxhighlight lang="python">
import tkinter as tk
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.Tk()
win = tk.Toplevel(root)
win.title("Centered!")
center(win)
root.mainloop()
</syntaxhighlight>
<br />
|