效果如下:
代码如下 :
import tkinter as tk
from win32api import GetSystemMetrics
# 传入GUI窗口大小(分辨率)计算出窗口居中的位置
def winPos(width, height):
#获取电脑屏幕分辨率
win_res = [GetSystemMetrics(0), GetSystemMetrics(1)]
x_position = (win_res[0] - width)//2
y_position = (win_res[1] - height) // 2
return x_position, y_position
def test_GUI():
root = tk.Tk()
root.title("我的工具")
root_width = 300
root_height = 300
pos = winPos(root_width, root_height)
root.geometry(f‘{root_width}x{root_height}+{pos[0]}+{pos[1]}‘)
tk.mainloop()
if __name__ == ‘__main__‘:
test_GUI()
原文:https://www.cnblogs.com/happy-xiaoxiao/p/10452494.html