让您的Tkinter窗口保持屏幕居中显示

import tkinter as tk

root = tk.Tk()
# 获取当前屏幕长宽
screenwidth = root.winfo_screenwidth()
screenheight = root.winfo_screenheight()
# 设定窗口的大小(长 * 宽)
width = 240
height = 180
# 设置窗口在屏幕居中
size = "%dx%d+%d+%d" % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
root.geometry(size)
root.mainloop()

 

posted @ 2020-03-13 16:10  清酒伴歌谣  阅读(929)  评论(0编辑  收藏  举报