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()