I have tried to find a solution online but was not successful so I hope you can provide me a short and clear solution.
I want to execute the function change_value()
after a button displayed on the window was pressed. After the execution, the window should be closed and the for-loop continued.
I am not asking for a way to close the window immediately after pressing the button which is absolutely trivial.
Thanks!
root = tkinter.Tk()
variable = 0
def change_value(value):
global variable
variable = value
for iteration in range(0, 10):
frame = tk.Toplevel()
tk.Button(frame, text = 'Button 1', command = change_value(2)).pack()
tk.Button(frame, text = 'Button 2', command = change_value(1)).pack()
print(variable)
###Close window and continue with the for-loop after a button has been pressed