PySimpleGui - 如何从输入文本框中删除文本

PySimpleGui - how do you remove text from input text box

PySimpleGui如何清除输入框的文字?我正在尝试 window ['-INPUT-'] ('') 但我收到一个关键错误。我想要它,以便在每次迭代后将框中的文本替换为空字符串,这样用户就不必自己删除文本。

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.

啊!

有一个参数专门用于此目的。

设置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()