gpt4 book ai didi

python - 如何指定 Tkinter 窗口打开的位置?

转载 作者:IT老高 更新时间:2023-10-28 20:34:49 27 4
gpt4 key购买 nike

如何根据屏幕尺寸告诉 Tkinter 窗口在哪里打开?我希望它在中间打开。

最佳答案

此答案基于 Rachel's answer .她的代码最初无法正常工作,但经过一些调整,我能够修复错误。

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

关于python - 如何指定 Tkinter 窗口打开的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14910858/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com