[英]How to clear a window in PySimpleGUI
I am using PySimpleGUI to build a GUI.我正在使用 PySimpleGUI 构建一个 GUI。 How do you clear all the widgets on the window?如何清除 window 上的所有小部件? In tkinter you have the code:在 tkinter 你有代码:
widget.destroy()
If you attempt this in PySimpleGUI you get the error:如果您在 PySimpleGUI 中尝试此操作,则会收到错误消息:
NameError: name 'RWG' is not defined
if my widget is called RWG
.如果我的小部件被称为RWG
。 I tried making RWG
a global
variable but I got the same error.我尝试将RWG
global
变量,但我得到了同样的错误。 Can I have some help?我可以帮忙吗? My code that gets the error:我得到错误的代码:
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()
I would appreciate any help我将不胜感激任何帮助
You can clear elements with:您可以使用以下方法清除元素:
window.FindElement(key).Update('')
Have you tried this?你试过这个吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.