Oct-20-2020, 11:05 AM
Thank you for your replies. I have learnt something from both of them.
I could pass the button as an argument as you suggest deanhistad but I need to configure up to 20 buttons, so I would prefer them to be configured in a loop.
Which using partial functions does. I've never come across partial functions or the Functools module before. Having researched it a bit I can see you need to generate a new function of the partial function, and call the new function supplying any if needed additional arguments. Can't quite see how a new function of the partial(do_something,x) is made/called when a button is clicked.
Another puzzle your solution has produced is why command = lambda:do_something(x) does not work. Why do you need to use a partial function. You would think that x, the list index basically, would be passed to the do_something function and the correct button would be actioned. What happens is the same as the Class scenario where the last button made is always actioned which ever button is clicked.
Anyway, having got all that clear in my mind, it's great when solutions provide more questions, that's how we learn.
I could pass the button as an argument as you suggest deanhistad but I need to configure up to 20 buttons, so I would prefer them to be configured in a loop.
Which using partial functions does. I've never come across partial functions or the Functools module before. Having researched it a bit I can see you need to generate a new function of the partial function, and call the new function supplying any if needed additional arguments. Can't quite see how a new function of the partial(do_something,x) is made/called when a button is clicked.
Another puzzle your solution has produced is why command = lambda:do_something(x) does not work. Why do you need to use a partial function. You would think that x, the list index basically, would be passed to the do_something function and the correct button would be actioned. What happens is the same as the Class scenario where the last button made is always actioned which ever button is clicked.
Anyway, having got all that clear in my mind, it's great when solutions provide more questions, that's how we learn.