Reputation: 847
I don't really know to set a variable by pressing a button in python. For example:
done = False
...
range_button = Button(self.parent, text="start", command=lambda....
...
while done:
.....
But i don't really know how to do something like this in python, any help?
Upvotes: 0
Views: 1679
Reputation: 385940
There's nothing special about doing this with Tkinter -- if done is a global variable (or an instance variable) just set it to whatever value you want. The important part is, it must be a non-local variable.
range_button = Button(..., command=stop_loop)
def stop_root():
global done
done = True
def something_else():
global done
while !done:
...
Strictly speaking, you don't need the global done
statement in the function with the loop, since that function isn't changing the value of the variable. However, I think it makes the intent of your code a little more evident.
Upvotes: 1