Hey, so I'm building a minesweeper clone in python, no real reason than to work on programming and I was having a slight problem with tkinter or lambdas, I'm not sure which
Here is my current GUI code
https://gist.github.com/TechyZeldaNerd/a2d3f27fa9349c6ea7291477a00a2533
Currently, I'm creating plenty of buttons, each with a theoretically unique callback. The problem is that all the callbacks end up with the same parameters, the parameters of the last button (in this case, i = j = 15)
I suspect that it might be because of this line
I suspect the variables i and j in the lambda aren't evaluated when the buttons are created. Is there be a way to force them to be evaluated when I create the button, or will I have to work around this
Edit: Nevermind, python lambdas are late binding, I just had to create a copy of the variable in the lambda
Here is my current GUI code
https://gist.github.com/TechyZeldaNerd/a2d3f27fa9349c6ea7291477a00a2533
Currently, I'm creating plenty of buttons, each with a theoretically unique callback. The problem is that all the callbacks end up with the same parameters, the parameters of the last button (in this case, i = j = 15)
I suspect that it might be because of this line
Code:
tmp = tk.Button(text = 'x: ' + str(i) + " y: " + str(j), command = lambda: check(i,j))Edit: Nevermind, python lambdas are late binding, I just had to create a copy of the variable in the lambda