2013-06-27 58 views
1

我将如何建立一个Tkinter的窗口坐标(500×500大小),这样的(0,0)点在左下角,而(500×500)是在右上角?谷歌没有太多的帮助。设置的Tkinter窗口的坐标

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

不要忘记在最后调用'mainloop',用:'root.mainloop()' –

回答

1

AFAIK你不能改变这一点,但它很容易,计算你在找什么。

首先,我们必须注意,即使0,0位于画布的左下角或左上角,x的坐标也是一样 - 所以我们不必做任何事情那。

y将会改变,这将取决于画布的宽度。所以首先,我们必须存储宽度并使用它来获得翻译后的y值。

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

现在,我们可以用这个宽度计算的,所以我们说,要在20,12加点和帆布为500,500,则x不会改变,我们有翻译y

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