This article applies to the scenario: you want to use Tkinter to develop interface programs and screen centering, but did not find the corresponding API.
I've been playing with Tkinter for the past two days, and I feel good about it, but I've been searching the internet for a long time for the problem of centering the screen, and I can't find it.
Find an answer to your question and finally had no choice but to look at its documentation and implement it in my own way.
The method is very earthy, is to get the initialization of the form size and screen size, and then through the calculation to get the large body value.
Here is the code:
#! /usr/bin/python
'''
File :
Author : Mike
E-Mail : Mike_Zhang@
'''
from Tkinter import *
rt = Tk()
(False,False)
("Screen center")
() # update window ,must do
curWidth = rt.winfo_reqwidth() # get current width
curHeight = rt.winfo_height() # get current height
scnWidth,scnHeight = () # get screen width and height
# now generate configuration information
tmpcnf = '%dx%d+%d+%d'%(curWidth,curHeight,
(scnWidth-curWidth)/2,(scnHeight-curHeight)/2)
(tmpcnf)
()
Okay, that's it. I hope that helps.