How to clear a window in PySimpleGUI

Question:

I am using PySimpleGUI to build a GUI. How do you clear all the widgets on the window? In tkinter you have the code:

widget.destroy()

If you attempt this in PySimpleGUI you get the error:

NameError: name 'RWG' is not defined

if my widget is called RWG. I tried making RWG a global variable but I got the same error. 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

Asked By: Thomas

||

Answers:

You can clear elements with:

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

Have you tried this?

Answered By: Sascha Höche
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.