Skip to content Skip to sidebar Skip to footer

How To Read The Result Of A Radiobutton With Python

I would like to add some widgets like Radiobutton with Python2.7 but my code does not compile. What I want is mainly when I click on IN or OUT is to display the result of radio.on_

Solution 1:

The line print radio.on_clicked(sel) does not make any sense at all. radio.on_clicked(sel) registers a callback in the matplotlib callback registry and returns the number of this callback in the register. So the first time you call it, it may return 1, second time 2 etc. The more often you do it, the more of the same callbacks you end up having in the callback registry, whereas one of them is enough.

It could be that the following is doing what you need.

import pylab as plt
from matplotlib.widgets import Button
from matplotlib.widgets import RadioButtons

defsel(var):
    if var == "IN":
        print"IN"returnTrueelif var == "OUT":
        print"OUT"returnFalsedefpre(event):
    print"You clicked the button"

axplot = plt.axes([0.11,0.92,0.08,0.07])
bplot = Button(axplot, 'Plot')
bplot.on_clicked(pre)

choice = plt.axes([0.44,0.92,0.08,0.07])
radio = RadioButtons(choice, ('IN', 'OUT'))
radio.on_clicked(sel)

plt.show()

Post a Comment for "How To Read The Result Of A Radiobutton With Python"