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