python - Change matplotlib Button color when pressed -


i'm running animation using matplotlib's funcanimation display data (live) microprocessor. i'm using buttons send commands processor , color of button change after being clicked, can't find in matplotlib.widgets.button documentation (yet) achieves this.

class command:      def motor(self, event):     serial['serial'].write(' ')     plt.draw()  write = command() bmotor = button(axmotor, 'motor', color = '0.85', hovercolor = 'g') bmotor.on_clicked(write.motor)            #change button color here 

just set button.color.

e.g.

import matplotlib.pyplot plt matplotlib.widgets import button import itertools   fig, ax = plt.subplots() button = button(ax, 'click me!')  colors = itertools.cycle(['red', 'green', 'blue'])  def change_color(event):     button.color = next(colors)     # if want button's color change it's clicked, you'll     # need set hovercolor, well, mouse still on     button.hovercolor = button.color     fig.canvas.draw()  button.on_clicked(change_color)  plt.show() 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -