This article mainly introduces the screen Center method of the Tkinter program written in Python. Tkinter is a python module and an interface that calls TclTk. it is a cross-platform GUI interface for scripts, if you want to use Tkinter to develop the interface program and center the screen, you can refer to the following application scenarios: you cannot find the corresponding API.
I have been playing Tkinter these two days. I feel good, that is, the problem of center of the screen has not been found online for a long time.
Find the answer and there is no way at last. read its documentation and implement it in your own way.
The method is very earthy, that is, get the initial form size and screen size, and then obtain the general value through calculation.
The following code is used:
The code is 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' % (curWidth, curHeight,
(ScnWidth-curWidth)/2, (scnHeight-curHeight)/2)
Rt. geometry (tmpcnf)
Rt. mainloop ()
Okay, that's all. I hope it will help you.