Reputation: 1859
Is there a way to be able to get the input from an InputText()
without having to rely on a button press? I am trying to make a form where the submit button is only available when the input text is not empty, however the only way to get the input from InputText()
that I have found is with a button which needs to be clicked in order for me to receive the input.
Upvotes: 1
Views: 1180
Reputation: 13061
Decide what event by yourself to send the content of the Input element.
import PySimpleGUI as sg
layout = [[sg.Input(key='-IN-'), sg.Button('Submit')]]
window = sg.Window('Title', layout)
event, values = window.read()
if event == 'Submit':
print(values['-IN-'])
window.close()
bind_return_key=True
import PySimpleGUI as sg
layout = [[sg.Input(key='-IN-'), sg.Button('Submit', bind_return_key=True)]]
window = sg.Window('Title', layout)
event, values = window.read()
if event == 'Submit':
print(values['-IN-'])
window.close()
'<Return>'
to your Input element.import PySimpleGUI as sg
layout = [[sg.Input(key='-IN-')]]
window = sg.Window('Title', layout, finalize=True)
window['-IN-'].bind('<Return>', ' ENTER')
event, values = window.read()
if event == '-IN- ENTER':
print(values['-IN-'])
window.close()
enable_events=True
import PySimpleGUI as sg
layout = [[sg.Input(enable_events=True, key='-IN-')]]
window = sg.Window('Title', layout)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break
elif event == '-IN-':
print(values['-IN-'])
window.close()
Upvotes: 3