Buttons have their own coordinate system according to the “grid_location” method?

后端 未结 1 1307
天涯浪人
天涯浪人 2021-01-13 05:12

I\'m trying to use the grid_location method, from the Grid Geometry Manager, in Tkinter, but it seems that I\'m doing something wrong.

Here\'s

相关标签:
1条回答
  • 2021-01-13 05:30

    You are correct that each button "has it's own coordinate system". More accurately, though, the event.x and event.y values are relative to the widget associated with the event rather than the widget's parent or the root window.

    If you really do need the row and column that the widget is in you can use grid_info to get the row and column of the widget associated with the event. For example:

    def mouse(event):
        grid_info = event.widget.grid_info()
        print("row:", grid_info["row"], "column:", grid_info["column"])
    
    0 讨论(0)
提交回复
热议问题