-1

I'm creating a GUI and I had an issue. My GUI is going to interact with the users, so depending on the user's input I want a button to appear. How can I do it? Because so far I can only make the button appear once the window opens.

For example, on the image below I have a sg.InputText isolated, but what I realy want is that this widget appears only after the first sg.InputText is filled.

enter image description here

Raul Lopes
  • 17
  • 2

1 Answers1

0

Create a Button element with option visible=False, update it with visible=True when the value of Input element not empty.

import PySimpleGUI as sg

layout = [
    [sg.Image(data=sg.EMOJI_BASE64_HAPPY_JOY),
     sg.Text("TRAINING PROGRAM"), sg.Push(),
     sg.Button("Check", visible=False)],
    [sg.Text("Pass the badge on the reader:"),
     sg.Input('', enable_events=True, key='-INPUT-')],
]
window = sg.Window('Title', layout, finalize=True)
shown = False

while True:

    event, values = window.read()

    if event == sg.WIN_CLOSED:
        break
    elif event == '-INPUT-':
        if values[event] != '':
            if not shown:
                shown = True
                window['Check'].update(visible=True)
        else:
            shown = False
            window['Check'].update(visible=False)

window.close()
Jason Yang
  • 11,284
  • 2
  • 9
  • 23