In the past, to build a radio button with Matplotlib Widgets and print the pushed button name to the terminal I have done this:
import matplotlib.pyplot as plt
from matplotlib.widgets import RadioButtons
def update(val):
print(rb.value_selected)
fig.canvas.draw_idle()
fig, ax = plt.subplots(1, 1)
ax = plt.axes([0.5, 0.4, 0.1, 0.15], facecolor='gray')
rb = RadioButtons(ax, ('pi', '42'), active=0)
rb.on_clicked(update)
plt.show()
The changing something on the radio button always generates an event.
Looking at the example in this answer it seems I need to also include an extra Read button; the visible appearance of the radio buttons can be different than what my script thinks the user wants until the user presses Read. Manipulating the radio buttons does not seem to generate an event. You have to then push a second button that says Hey! I've made up my mind, now take a look!
import PySimpleGUI as sg
layout = [[sg.Radio('pi', 'num', default=True) ,
sg.Radio('42', 'num')],
[sg.Button('Read')]]
window = sg.Window('Radio Button Example', layout)
while True: # Event Loop
event, values = window.Read()
if event in (None, 'Cancel'):
break
print(event, values)
window.close()
This comment says
I think you've hit either a bug or the Radio Buttons enable_events isn't implemented. I thought it was but may not be on Qt. I'll make it a priority and look at the code.
which makes me think there ought to be a way to generate an event in PySimpleGUI when a radio button is changed without need for a separate button, but I can't figure out if there is one.
Question: Is there a way for PySimpleGUI Radio Buttons to generate events when changed?

