0

so what I am trying to do right now is, if I click one of the radio buttons, some information about the Method should automatically show in the GUI but i cant seem to get it right. I thought maybe i could get it done by using an if statement but nothing happens.

import PySimpleGUI as sg

# List for Radiobuttons
radio_choices = ["Method 1", "Method 2", "Method 3", "Method 4"]

layout = [[sg.Text("Choose Method")],
          *[[sg.Radio(text, 1), ] for text in radio_choices],
          [sg.Button("Start"), sg.Button("Stop"), sg.Button("Exit")]


          ]

window = sg.Window("Choose Method", layout, size=(350, 350))

while True:
    event, values = window.Read()

    
    if event == "Exit" or event == sg.WIN_CLOSED:
        break

    if event == radio_choices[0]:
        sg.Text("Method 1 description")
window.close()
Hai
  • 1

1 Answers1

0

Try this :

import PySimpleGUI as sg

# List for Radiobuttons
radio_choices = ["Method 1", "Method 2", "Method 3", "Method 4"]

layout = [[sg.Text("Choose Method")],
          *[[sg.Radio(text, 1),sg.Text('this is ' + text ,key=text, visible=False) ] for text in radio_choices],
          [sg.Button("Start"), sg.Button("Stop"), sg.Button("Exit")]


          ]

window = sg.Window("Choose Method", layout, size=(350, 350))

while True:
    event, values = window.Read()

    print(event, values)
    if event == "Exit" or event == sg.WIN_CLOSED:
        break

    if event == 'Start':
        for k,value in values.items():
            if value == True:
                window[radio_choices[k]].update(visible=True)
            else : 
                window[radio_choices[k]].update(visible=False)
window.close()
Bhargav Desai
  • 941
  • 1
  • 5
  • 17
  • Thank you, but its not quite what i had in mind. The thought also was to add a description in what the method does. in layout i added another button called "sg.Button("Information") to output the text. Do you think it is possible to put the output text in a specific area and not beside the radio button? – Hai Aug 11 '20 at 15:49