Python 3, Tkinter 8.6. GUI examples in Windows 10
When your first window loads in Tkinter it will generally appear slightly offset from the top left-hand corner of the screen. This is a fairly counter-intuitive location and most of the GUI driven programs that I run usually open at the centre of the page or a little higher than the center.
If you want a primer of window positioning, check out the following tutorial:
How Do I Change the Size and Position of the Main Window in Tkinter and Python 3
In Python 3, to put the main window in the center of the screen I use the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# Python 3, Tkinter 8.6 # Centering Root Window on Screen from tkinter import * root = Tk() # Gets the requested values of the height and widht. windowWidth = root.winfo_reqwidth() windowHeight = root.winfo_reqheight() print("Width",windowWidth,"Height",windowHeight) # Gets both half the screen width/height and window width/height positionRight = int(root.winfo_screenwidth()/2 - windowWidth/2) positionDown = int(root.winfo_screenheight()/2 - windowHeight/2) # Positions the window in the center of the page. root.geometry("+{}+{}".format(positionRight, positionDown)) root.mainloop() |

Continue reading “How to Center the Main Window on the Screen in Tkinter with Python 3”