I have three white buttons [A,B,C]. When either of these buttons are clicked on they should turn green instantly. When multiple buttons are clicked on sequentially, only the most recently clicked on should turn green, the others should return to their original white state.
I've read this page Change matplotlib Button color when pressed, but it didn't help. Here is the code that I've written. At the moment the button isn't even turning green. I'm using Matplotlib 2.0.
from matplotlib.widgets import Button
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
button_axcut={}
button={}
button_axcut['A'] = plt.axes([0.25,0.5, 0.1, 0.1])
button['A'] = Button(button_axcut['A'] ,'A', color='white')
button_axcut['B'] = plt.axes([0.45,0.5, 0.1, 0.1])
button['B'] = Button(button_axcut['B'] ,'B', color='white')
button_axcut['C'] = plt.axes([0.65,0.5, 0.1, 0.1])
button['C'] = Button(button_axcut['C'],'C', color='white')
def A_clicked(event):
print('A')
button['A'].ax.set_facecolor('green')
button['B'].ax.set_facecolor('white')
button['C'].ax.set_facecolor('white')
button['A'].ax.figure.canvas.draw()
button['B'].ax.figure.canvas.draw()
button['C'].ax.figure.canvas.draw()
def B_clicked(event):
print('B')
button['A'].ax.set_facecolor('white')
button['B'].ax.set_facecolor('green')
button['C'].ax.set_facecolor('white')
button['A'].ax.figure.canvas.draw()
button['B'].ax.figure.canvas.draw()
button['C'].ax.figure.canvas.draw()
def C_clicked(event):
print('C')
button['A'].ax.set_facecolor('white')
button['B'].ax.set_facecolor('white')
button['C'].ax.set_facecolor('green')
button['A'].ax.figure.canvas.draw()
button['B'].ax.figure.canvas.draw()
button['C'].ax.figure.canvas.draw()
button['A'].on_clicked(A_clicked)
button['B'].on_clicked(B_clicked)
button['C'].on_clicked(C_clicked)
