这两天玩了玩tkinter,感觉不错,就是屏幕居中这个问题在网上搜了很长时间也没
找到答案,最后没办法,看它的文档,用自己的方法实现了。
方法很土,就是获取初始化的窗体大小和屏幕大小,再通过计算得到大体值。
以下是代码:
复制代码 代码如下:
#! /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()
好,就这些了,希望对你有帮助。
