4
我试图使用grid_location
方法,从网格几何经理,在Tkinter的,但似乎我做错了。按钮有根据“grid_location”的方法自己的坐标系?
这里是我的代码:
from tkinter import *
root = Tk()
b=Button(root, text="00")
b.grid(row=0, column=0)
b2=Button(root, text="11")
b2.grid(row=1, column=1)
b3=Button(root, text="22")
b3.grid(row=2, column=2)
b4=Button(root, text="33")
b4.grid(row=3, column=3)
b5=Button(root, text="44")
b5.grid(row=4, column=4)
def mouse(event):
print(event.x, event.y)
print(root.grid_location(event.x, event.y))
root.bind("<Button-1>", mouse)
root.mainloop()
当我点击按钮之外,它的工作原理,但是当我点击任何按钮里面,似乎每个按钮都有自己的坐标系。因此,尽管代码中的每个按钮都位于(0,0)单元格中,但它们都位于常规网格中。
谢谢布莱恩,工作完美。我之前尝试过get_info,但不知道如何使用它。很好的解释。 – 2011-05-23 21:04:32