文章目录
- 代码
- 效果
代码
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17import tkinter as tk def center_window(root, width, height): screenwidth = root.winfo_screenwidth() # 获取显示屏宽度 screenheight = root.winfo_screenheight() # 获取显示屏高度 size = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2) # 设置窗口居中参数 root.geometry(size) # 让窗口居中显示 root = tk.Tk() root.title('测试窗口') center_window(root, 300, 100) # 居中时需要同时设置窗体大小 tk.mainloop()
效果
最后
以上就是义气大树最近收集整理的关于tkinter 窗口屏幕居中显示的全部内容,更多相关tkinter内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复