1# Python 3, Tkinter 8.6
2# Centering Root Window on Screen
3
4from tkinter import *
5
6root = Tk()
7
8# Gets the requested values of the height and widht.
9windowWidth = root.winfo_reqwidth()
10windowHeight = root.winfo_reqheight()
11print("Width",windowWidth,"Height",windowHeight)
12
13# Gets both half the screen width/height and window width/height
14positionRight = int(root.winfo_screenwidth()/2 - windowWidth/2)
15positionDown = int(root.winfo_screenheight()/2 - windowHeight/2)
16
17# Positions the window in the center of the page.
18root.geometry("+{}+{}".format(positionRight, positionDown))
19
20
21root.mainloop()
22