Clearing out an existing widget in tkinter

[Rusty user question :slight_smile: ]

Got a treeview in a frame in a function that’s called from a menu option. I’m trying to remember how to deal with the situation where the same menu option gets called more than once. Right now, another (2nd, 3rd etc) instance of the treeview is being created and painted onscreen at each call.

I was trying to test for the existence of the frame with winfo_exists and if true destroy it before creating a new frame in the next line. But then of course Python throws an error with the code because I’m trying to reference the frame before it’s been created. Is that a sufficient description of the issue?

How should I be dealing with this please?

Hi John,

your function triggered by a menu option should be a method of a class and your treeview variable should be an attribute of the very same class. Said attribute should be initialised with None in the init method of said class and when your method is triggered, said method can check whether said attribute still contains None or already contains an treeview instance. Or alike…

Have Fun, Dominik