gpt4 book ai didi

python - 设置 tkinter 窗口的坐标

转载 作者:太空宇宙 更新时间:2023-11-03 18:55:33 25 4
gpt4 key购买 nike

如何设置 tkinter 窗口(大小 500x500)的坐标,使 (0,0) 点位于左下角,(500x500) 点位于右上角? Google 并没有提供太多帮助。

def graphDisplay(distance, elevation):
'''draws up the graph.'''

#creates a window
root = Tk()

#sets the name of the window
root.title("Graph")

#sets the size of the window
root.geometry("500x500")

#sets the background of the window
root.configure(background='green')

#create a canvas object to draw the circle
canvas = Canvas(root)

#runs the program until you click x
root.mainloop

最佳答案

据我所知,您无法更改这一点,但计算您要查找的内容非常容易。

首先,我们必须注意,即使 0,0 位于左下角或左上角,x 坐标也是相同的 Canvas 的角落 - 所以我们不必对此做任何事情。

但是y会改变,这取决于 Canvas 的宽度。因此,首先,我们必须存储宽度并使用它来获取翻译后的 y 值。

width = 500
root.geometry('500x{}'.format(width))

现在我们可以用这个宽度来计算,假设你想在20,12处添加一个点, Canvas 是500,500,那么x 不会改变,我们必须翻译 y:

translated_y = width - 12  # which will be: 500 - 12 = 488

关于python - 设置 tkinter 窗口的坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17346981/

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