程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

2023-05(2)

Tkinter程序屏幕居中

发布于2019-09-05 18:02     阅读(1377)     评论(0)     点赞(13)     收藏(3)


本文适用场景:想用Tkinter开发界面程序并屏幕居中,但没找到相应的API。

这两天玩了玩Tkinter,感觉不错,就是屏幕居中这个问题在网上搜了很长时间也没
找到答案,最后没办法,看它的文档,用自己的方法实现了。

方法很土,就是获取初始化的窗体大小和屏幕大小,再通过计算得到大体值。
以下是代码:

1 # ! /usr/bin/python
2 '''
3 File : screenCenter.pyw
4 Author : Mike
5 E-Mail : Mike_Zhang@live.com
6 '''
7 from Tkinter import *
8
9 rt = Tk()
10 rt.resizable(False,False)
11 rt.title( " Screen center ")
12
13 rt.update() # update window ,must do
14 curWidth = rt.winfo_reqwidth() # get current width
15 curHeight = rt.winfo_height() # get current height
16 scnWidth,scnHeight = rt.maxsize() # get screen width and height
17 # now generate configuration information
18 tmpcnf = ' %dx%d+%d+%d '%(curWidth,curHeight,
19 (scnWidth-curWidth)/2,(scnHeight-curHeight)/2)
20 rt.geometry(tmpcnf)
21 rt.mainloop()

好,就这些了,希望对你有帮助。


原文链接:http://www.cnblogs.com/MikeZhang/archive/2012/01/30/TkinterScreenCenter.html

所属网站分类: 技术文章 > 博客

作者:放羊人

链接:https://www.pythonheidong.com/blog/article/96415/54484386352485b4eb0d/

来源:python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

13 0
收藏该文
已收藏

评论内容:(最多支持255个字符)