Reputation: 33
How do you clear text in an input box PySimpleGui? I'm trying window ['-INPUT-'] ('') but I recieve a key error. I want it so that the text in the box gets replaced with an empty string after each iteration so the user doesn't have to delete the text themselves.
Upvotes: 2
Views: 7696
Reputation: 5754
I want it so that the text in the box gets replaced with an empty string after each iteration so the user doesn't have to delete the text themselves.
Ah!
There is a parameter meant specifically for this purpose.
Set do_not_clear=False
import PySimpleGUI as sg
layout = [ [sg.Text('Input element that clears after every read')],
[sg.Input('Initial text', key='-I-', do_not_clear=False)],
[sg.Button('Go'), sg.Button('Exit')] ]
window = sg.Window('Input auto-clear', layout)
while True: # Event Loop
event, values = window.read()
if event in (None, 'Exit'):
break
print(event, values)
window.close()
Upvotes: 4