This article applies to the scenario: want to use Tkinter development interface Program and Screen center, but did not find the corresponding API.
These two days play tkinter, feel good, is the screen center this problem searched the internet for a long time also did not
Find the answer, finally no way, look at its documents, in its own way to achieve.
The method is very earthy, that is, to get the initialized form size and screen size, and then calculate the approximate value.
Here's the code:
Copy the 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 ()
All right, that's it, I hope it helps you.