[英]set the coordinates of a tkinter window
我如何设置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您无法更改,但是很容易计算出您想要的内容。
首先,我们必须注意,即使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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.