设置tkinter窗口的坐标

2024-07-01 07:02:06 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

Tags: ofthetkinterdefsetsrootwindowgraph
1条回答
网友
1楼 · 发布于 2024-07-01 07:02:06

虽然你不能改变这一点,但很容易计算出你要找的东西。在

首先,我们必须注意,x坐标是相同的,即使0,0位于画布的左下角或左上角,所以我们不必对此做任何操作。在

但是y将发生变化,它将取决于画布的宽度。因此,首先,我们必须存储宽度并使用它来获得翻译后的y值。在

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

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

^{pr2}$

相关问题 更多 >

    热门问题