I'm trying to change a global variable in a click event with matplotlib. I spent too many hours solving this problem, and still nothing for now.
I tried this code:
def menu_event(event):
global state
state +=1
print(state)
def main():
# ...
b = Button(button_ax, name, color=color, hovercolor=font_color)
b.on_clicked(menu_event)
# ...
while True:
print(state)
state = 0
if __name__ == "__main__":
main()
But the state variable doesn't change!
What I get in the output is the following:
0
0
0
1 # A push of a button happened
0
0
0
2 # A push of a button happened
0
0
0
3 # A push of a button happened
0
0
# ...
So it makes "state" like a static variable of menu_event(event).
What am I doing wrong?