| | |
Center a Tkinter Window
Thread Solved |
Not knowing Tkinter that well, here is a somewhat simple minded approach:
[php]from Tkinter import *
def center_window(w=300, h=200):
# get screen width and height
ws = root.winfo_screenwidth()
hs = root.winfo_screenheight()
# calculate position x, y
x = (ws/2) - (w/2)
y = (hs/2) - (h/2)
root.geometry('%dx%d+%d+%d' % (w, h, x, y))
root = Tk()
center_window(500, 300)
root.mainloop()
[/php]
[php]from Tkinter import *
def center_window(w=300, h=200):
# get screen width and height
ws = root.winfo_screenwidth()
hs = root.winfo_screenheight()
# calculate position x, y
x = (ws/2) - (w/2)
y = (hs/2) - (h/2)
root.geometry('%dx%d+%d+%d' % (w, h, x, y))
root = Tk()
center_window(500, 300)
root.mainloop()
[/php]
drink her pretty
![]() |
Similar Threads
- Tkinter window background (Python)
- Tkinter or wxPython? (Python)
- Tkinter Window Full Size (Python)
- Fix Tkinter Widget Location (Python)
- Tkinter Window Fixed Size (Python)
Other Threads in the Python Forum
- Previous Thread: Listbox in Tkinter python
- Next Thread: get text input from shell cursor
| Thread Tools | Search this Thread |
abrupt ansi anti apache approximation array assignment backend beginner binary bluetooth book builtin calculator character code converter countpasswordentry curved customdialog dan08 dictionaries dictionary dynamic examples exe file float format function gnu graphics gui heads homework ideas import inches input java launcher library line lines linux list lists loop mouse mysqlquery number numbers numeric output parsing path phonebook plugin pointer port prime programming progressbar projects py2exe pygame pysimplewizard python random recursion redirect scrolledtext software statictext statistics string strings sum table terminal text textarea thread threading time tlapse trick tricks tuple tutorial twoup ubuntu unicode urllib urllib2 variable wordgame write wxpython xlib






