Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tkinter in Python - Remove widget from active window

I'm trying to remove a Tkinter progress bar widget from an active window (after the GUI window using Tkinter has been initialized). I'm using a Tkinter Frame for my window. I've initialized the progress bar as pb, as below.

pb = ttk.Progressbar(root,orient ="horizontal",length = 540, mode ="determinate")

And then I've tried two different methods to get rid of the progress bar. The line below causes the window to freeze and stop responding when I try to use it after the GUI is initialized.

pb.pack_forget()

The line below causes only a middle section of the progress bar to disappear, but you can still see the two sides of it.

pb.destroy()

Is there any way I could get this widget to disappear after the Frame has been initialized?

like image 462
Jon Bailey Avatar asked Sep 13 '25 06:09

Jon Bailey


1 Answers

The specific answer to your question is that pack_forget, grid_forget or grid_remove are what you want if you want to make a widget temporarily invisible. Which one you choose depends on if you're using grid or pack, and whether or not you want grid to remember where it was so you can later put it back in the same spot.

destroy is what you want to call if you want to literally destroy the widget.

When used properly, none of those methods will cause your program to freeze. Without seeing your code, it's impossible to know what the root cause of the problem is.

like image 146
Bryan Oakley Avatar answered Sep 15 '25 21:09

Bryan Oakley