import tkinter as tk
root = tk.Tk() # create a Tk root window
w = 800 # width for the Tk root
h = 650 # height for the Tk root
# get screen width and height
ws = root.winfo_screenwidth() # width of the screen
hs = root.winfo_screenheight() # height of the screen
# calculate x and y coordinates for the Tk root window
x = (ws/2) - (w/2)
y = (hs/2) - (h/2)
# set the dimensions of the screen
# and where it is placed
root.geometry('%dx%d+%d+%d' % (w, h, x, y))
root.mainloop() # starts the mainloop
这个答案是基于Rachel's answer。她的代码最初不起作用,但经过一些调整,我能够修复错误。
试试这个
Source
前两个参数是窗口的宽度和高度。最后两个参数是x和y屏幕坐标。您可以指定所需的x和y坐标
相关问题 更多 >
编程相关推荐