I generated a grid of buttons with row and col. I then bind the buttons with a left and right click and pass the row and col of the clicked button but could not make it work.
Here is what i did.
def initialize(self):
self.grid()
frame = gui.Frame(self)
frame.pack()
for col in range(x_length):
for row in range(y_length):
button = gui.Button(frame,text=str(col) + ":" + str(row))
button.grid(column=col,row=row)
button.bind('<Button-1>',lambda col=col, row=row: self.on_left_click(self, row, col))
button.bind('<Button-3>',lambda col=col, row=row: self.on_right_click(self, row, col))
def on_left_click(self, event, row, col):
self.some_function(event, "left", row, col)
def on_right_click(self, event, row, col):
self.some_function(event, "right", row, col)
def some_function(self, event, click, row, col):
print('{} click on {}:{}'.format(click, row, col))
It is retrieving the row coordinate but not the col coordinate.
right click on <tkinter.Event object at 0x0000000002FA44E0>:6
left click on <tkinter.Event object at 0x0000000002FA44E0>:4
right click on <tkinter.Event object at 0x0000000002FA44A8>:7
I am learning Python and any help is appreciated. I already saw similar problems posted with answers but this might be different.