您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Python写的Tkinter程序屏幕居中方法

2024/3/11 3:48:20发布27次查看
本文适用场景:想用tkinter开发界面程序并屏幕居中,但没找到相应的api。
这两天玩了玩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()
好,就这些了,希望对你有帮助。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product