如何在 PySimpleGUI 中清除 window

How to clear a window in PySimpleGUI

我正在使用 PySimpleGUI 构建 GUI。如何清除 window 上的所有小部件?在 tkinter 中你有代码:

widget.destroy()

如果您在 PySimpleGUI 中尝试这样做,您会得到错误:

NameError: name 'RWG' is not defined

如果我的小部件名为 RWG。我尝试将 RWG 设为 global 变量,但我遇到了同样的错误。我能帮忙吗? 我的代码出现错误:

def oof():
    RWG.destroy()


import PySimpleGUI as sg
sg.theme("DarkAmber")
layout = [[sg.Text("Don't Even Try!!!")],
          [sg.Button("RWG")]]

window = sg.Window("Don't Even Try It", layout).Finalize()
window.Maximize()

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

    if event == "RWG":
        oof()

如有任何帮助,我将不胜感激

您可以使用以下方法清除元素:

window.FindElement(key).Update('')

你试过吗?