先上代码:
from tkinter import *
root = Tk()
# 获取屏幕尺寸,使窗口位于屏幕中央
width = 380
heigh = 300
screenwidth = root.winfo_screenwidth()
screenheight = root.winfo_screenheight()
root.geometry('%dx%d+%d+%d'%(width, heigh, (screenwidth-width)/2, (screenheight-heigh)/2))
mainloop()
效果图
1)tkinter中控制界面的方法为genmetry,其参数为(‘窗口宽 x 窗口高 + 窗口位于x轴位置 + 窗口位于y轴位置)
2)winfo_screenwidth()和winfo_screenheight()分别是获取屏幕的宽度和高度(分辨率)