我是靠谱客的博主 义气大树,这篇文章主要介绍tkinter 窗口屏幕居中显示,现在分享给大家,希望可以做个参考。

文章目录

    • 代码
    • 效果

代码

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import 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内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(51)

评论列表共有 0 条评论

立即
投稿
返回
顶部