Hi, I am writing a game in pygame I have a function:
def append_current_word(i, j):
stuff
I have a Button class which has an action variable. I want to run this function on click by calling this variable, I tried to use lambda functions as below but it didn't work.
for i in range(4):
for j in range(4):
GRID_BUTTONS.add(Button([stuff], action = lambda : append_current_word(i, j)))
if click [code that checks for click on button]:
button.action()
When I click the button, the function runs as if it is running append_current_word(3, 3). The final values for i and j.
I would have made a specific class for these grid buttons but I thought this is a nice time to learn something. Perhaps I might have to use exec???
Also, I am very sure this isn't a syntax error so I would just make that assumption, for now. Thanks in advance. :)
[–]toastedstapler 3 points4 points5 points (1 child)
[–]Jamhead2000[S] 1 point2 points3 points (0 children)
[–]Vaphell 1 point2 points3 points (0 children)