2

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

Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52
Thomas
  • 1,214
  • 4
  • 18
  • 45
  • Please provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example), so we can reproduce the error and inspect. – ywbaek Apr 19 '20 at 15:37
  • I didn't downvote, but I assume it was done before you edited the question. – ywbaek Apr 23 '20 at 13:08
  • There can be various reasons, you might want to kindly ask for a feedback on your question. – ywbaek Apr 23 '20 at 13:56

1 Answers1

4

You can clear elements with:

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

Have you tried this?

Sascha Höche
  • 66
  • 1
  • 8
  • 2
    ** Warning - FindElement should not be used to look up elements. window[key] or window.find_element are recommended. ** – G. Trialonis Oct 28 '21 at 16:41