Skip to content Skip to sidebar Skip to footer

Make Pysimplegui Radio Buttons Generate Events

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.widg

Solution 1:

Generating events when something changes is specified by the enable_events parameter. Documented here : https://pysimplegui.readthedocs.io/en/latest/#radio-element

Example to try. Works for PySimpleGUIQt too.

import PySimpleGUI as sg

layout = [  [sg.Text('Radio Button Events')],
            [sg.Radio('1', 1, enable_events=True, key='R1'), sg.Radio('2',1, enable_events=True, key='R2')],
            [sg.Button('Go'), sg.Button('Exit')]  ]

window = sg.Window('Window Title', layout)

whileTrue:             # Event Loop
    event, values = window.read()
    print(event, values)
    if event in (None, 'Exit'):
        break
window.close()

Post a Comment for "Make Pysimplegui Radio Buttons Generate Events"