Code used below:
import PySimpleGUI as sg
layout1 = [
[sg.Radio('Test', "RADIO1", key = '_RADIO1_',
default = True, font = 50)],
[sg.Button('Ok', font = 50), sg.Button('Stop', font = 50)]
]
window = sg.Window('Read').Layout(layout1).Finalize()
while True:
window.Element('_RADIO1_').Update('NewTest')
button, values = window.Read()
exit()
Checklist boxes are used when either one or more options can either be checked or left unchecked.,Radio buttons are used when either one of the options must be selected,Radio buttons are other useful GUI items that offers options to the user. The main difference is you can select multiple radio buttons. It forces you to opt in for only one of the options in the same group.,Often, software requires additional input from the user and main mechanisms are coded to be able to respond to those preferences. In this case, boolean selection items such as radio buttons or checklists become incredibly useful. In principal:
[sg.Checkbox('My Checkbox',
default = True)]
layout = [
[sg.Button('Hello World', size = (20, 4))],
[sg.Checkbox('Print On:',
default = True)]
]
import PySimpleGUI as sg layout = [ [sg.T("")], [sg.T(" "), sg.Button('Hello World', size = (20, 4))], [sg.T("")], [sg.T(" "), sg.Checkbox('Print On:', default = True)] ] # # #Setting Window window = sg.Window('Push my Buttons', layout, size = (300, 200)) # # #Showing the Application, also GUI functions can be placed here. while True: event, values = window.read() if event == sg.WIN_CLOSED or event == "Exit": break window.close()
layout = [
[sg.Button('Hello World', size = (20, 4))],
[sg.Checkbox('Print On:',
default = False, key = "-IN-")]
]
while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == "Exit":
break
elif values["-IN-"] == True:
print("Hello World")
import PySimpleGUI as sg layout = [ [sg.T("")], [sg.T(" "), sg.Button('Hello World', size = (20, 4))], [sg.T("")], [sg.T(" "), sg.Checkbox('Print On:', default = True, key = "-IN-")] ] # # #Setting Window window = sg.Window('Push my Buttons', layout, size = (300, 200)) # # #Showing the Application, also GUI functions can be placed here. while True: event, values = window.read() if event == sg.WIN_CLOSED or event == "Exit": break elif values["-IN-"] == True: print("Hello World") window.close()
I'm using PySimpleGUI in which I want to anycodings_radio-button update a radio button. According to the anycodings_radio-button documentation the radio button has an update anycodings_radio-button method. But somehow it doesn't work anycodings_radio-button properly.,Sounds like you're trying to change the anycodings_radio-button text that's next to an specific radio anycodings_radio-button button.,I wrote the following code which should anycodings_radio-button update the value of the radio button from anycodings_radio-button Test to NewTest. The result is still Test.,There are 3 things you can currently anycodings_radio-button change in a Radio button, the "state" anycodings_radio-button (true/false), disabled and visibility.
Code used below:
import PySimpleGUI as sg
layout1 = [
[sg.Radio('Test', "RADIO1", key = '_RADIO1_',
default = True, font = 50)],
[sg.Button('Ok', font = 50), sg.Button('Stop', font = 50)]
]
window = sg.Window('Read').Layout(layout1).Finalize()
while True:
window.Element('_RADIO1_').Update('NewTest')
button, values = window.Read()
exit()
After much trip & error experimenting, I finally got Radio Buttons working with PySimpleGUI.,Updated: May 27, 2020,There may be a simpler way, but this works for me:,©2020 by Coding Snippets. Proudly created with Wix.com
import PySimpleGUI as sg
EXTNS = ['JPG', 'ARW', 'TIF', 'DNG', 'PNG', 'PSD', 'All']
form = sg.FlexForm('Duplicate File Finder')
radio_buttons = [sg.Radio(EXTNS[0], 1, key = EXTNS[0],
default = True),
sg.Radio(EXTNS[1], 1, key = EXTNS[1]),
sg.Radio(EXTNS[2], 1, key = EXTNS[2]),
sg.Radio(EXTNS[3], 1, key = EXTNS[3]),
sg.Radio(EXTNS[4], 1, key = EXTNS[4]),
sg.Radio(EXTNS[5], 1, key = EXTNS[5]),
sg.Radio(EXTNS[6], 1, key = EXTNS[6])
]
layout = [
[sg.Text('Select a file extension for the search:', size = (30, 1),
font = ("Helvetica", 25))],
radio_buttons,
[sg.Submit(), sg.Cancel()]
]
button, values = form.Layout(layout).Read()
if button == "Submit":
for _ in values:
if values[_]:
print(_)