#Why doesn't it properly center the window? (Tkinter)

8 messages · Page 1 of 1 (latest)

golden fossil
#

Why doesn't it properly center the window? (Tkinter)

broken yacht
#

Hard to tell on my phone but it looks like the top left corner might be in the center?

golden fossil
#

yeah it does look like put the top left corner as the center

#

thanks for the observation I'll see what i can do tomorrow

golden fossil
#
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
x = (screen_width / 2) - (700 / 2)
y = (screen_height / 2) - (400 / 2)

root.geometry('%dx%d+%d+%d' % (700, 400, x, y))

this is the fix that I found, but can someone explain to me why this one works and the other attempts didn't?

broken yacht
#

Looks like it was positioning the top left in the middle then. 700/2 and 400/2 give you the center of the window. So the subtraction from the centre of the screen (screen_width / 2 and screen_height / 2) is moving the center of your window to the center of the screen