I've been messing about with this bit of code. Basically what it's
supposed to do is create these six buttons, which when clicked pass a parameter to a function and then call that function. The function basically removes one condition from a larger list depending on which button is clicked The problem is that the way I've written it, the functions runs automatically before the user actually clicks the button.
firstCond = '' condNames = ['1', '2', '3', '4', '5', '6'] for item in condNames: button = Button(frame, name = str(item), text = str(item), command = getCond(item)).pack() def getCond(par): firstCond = par conditions.remove(firstCond) print firstCond print conditions
So I want the function to run when the button is clicked, not automatically on its own. Now I know that the reason it does this is because of the brackets following getCond(item). However, I cannot see any other way of passing the parameter to the function.
Obviously, I could make separate functions for each condition, but I'm just wondering if I could do it more elegantly in this way? It would be a pain if I had 100 conditions instead of 6...