如何设置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
最佳答案
AFAIK您无法更改,但是很容易计算出您想要的内容。
首先,我们必须注意,即使x
在画布的左下角或左上角,0,0
坐标也是相同的-因此我们不必对那。
但是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