2013-06-27 56 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