让您的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()
原文地址:https://www.cnblogs.com/cxstudypython/p/12487151.html