Python tkinter窗口显示在屏幕中心代码

tk = tkinter.Tk()
# 设置窗口居中
width = 300
height = 100
screenwidth = tk.winfo_screenwidth()
screenheight = tk.winfo_screenheight()
alignstr = '%dx%d+%d+%d' % (width, height, (screenwidth-width)/2, (screenheight-height)/2)
tk.geometry(alignstr)

# 设置窗口大小不可改变
tk.resizable(width=False,height=False)
tk.mainloop()

你可能感兴趣的:(Python)