Hi I have a very specific code problem I would need a fresh pair of eyes to look at. I'm trying to make a GUI for an Othello game I programmed. I've just started and made green tiles that I will play the game in. To see that everything worked I made a simple function that is called every time one of the tiles is clicked. The function should then print the coordinates of the tile I just clicked to the console. However what it does is that it prints [7, 7]
. This of course are the coordinates of the very last tile created. Anyway I don't know what I'm doing wrong but my guess is that I don't fully understand the .bind()
function, thanks for any help.
Code:
from tkinter import *
def print_cors(event, cors):
print(cors)
class GridFrame:
def __init__(self, master):
board = Frame(master, height=500, width=800, bg="brown")
board.grid()
self.column_frame_list = [None]*8
for x in range(0, len(self.column_frame_list)):
self.column_frame_list[x] = [None]*8
for y in range(0, len(self.column_frame_list[x])):
self.column_frame_list[x][y] = Canvas(board, height=55, width=55, bg="green", bd=0, highlightthickness=0, relief='ridge')
self.column_frame_list[x][y].bind("<Button-1>", lambda event: print_cors(event, [x,y]))
self.column_frame_list[x][y].grid(row=y, column=x)
root = Tk()
root.wm_title("Reversi")
grid_frame = GridFrame(root)
root.mainloop()