This article applies to the scenario: you want to use the Tkinter development interface program and the screen center, but did not find the appropriate API.
These two days play tkinter, feel good, is the screen centered this problem on the Internet search for a long time also did not
Find the answer, there is no way, look at its documents, in their own way to achieve.
The way is to get the initialized form size and screen size, and then calculate the gross value.
Here's the code:
Copy Code code as follows:
#! /usr/bin/python
'''
File:screenCenter.pyw
Author:mike
E-mail:mike_zhang@live.com
'''
From Tkinter Import *
RT = Tk ()
Rt.resizable (False,false)
Rt.title ("Screen Center")
Rt.update () # Update window, must do
Curwidth = Rt.winfo_reqwidth () # Get current width
Curheight = Rt.winfo_height () # Get current height
Scnwidth,scnheight = Rt.maxsize () # Get screen width and height
# now generate configuration information
tmpcnf = '%dx%d+%d+%d '% (Curwidth,curheight,
(scnwidth-curwidth)/2, (Scnheight-curheight)/2)
Rt.geometry (TMPCNF)
Rt.mainloop ()
Well, that's all, I hope to help you.