Python Forum
make widgets disappear from tkinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
make widgets disappear from tkinter
#3
This is hideous.
globals()[f"unit_ent{self.count}"] = Entry()
globals()[f"unit_ent{self.count}"].grid(row=self.cur_row, column=5)
globals()[f"min_lbl{self.count}"] = Label(text="minutes")
globals()[f"min_lbl{self.count}"].grid(row=self.cur_row, column=6)
Whenever you have variable names that contain index numbers, even if they aren't dynamically generated, you should think "I need to use a list or a dictionary here."

I would rewrite the code above to look like this:
unit_ent.append(tk.Entry())
unit_ent[-1].grid(row=self.cur_row, column=5)
min_lbl.append(tk.Label(text="minutes"))
min_lbl[-1].grid(row=self.cur_row, column=6)
But to address your question.

If you want to erase a tkinter widget from a window, forget it. There is a pack_forget() for removing widgets that were packed, and a grid_forget() for widgets that are in a grid. You can also destroy the widgets if you don't want to use them anymore.

Since you want to remove entire rows, it might make sense to group your controls in widgets in rows, so all the controls for a given row are in a list.
Reply


Messages In This Thread
RE: make widgets disappear from tkinter - by deanhystad - Jan-30-2024, 09:40 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why I am getting ModuleNotFoundError when I make an Exe file for tkinter GUI? pymn 0 1,711 Apr-01-2022, 05:36 PM
Last Post: pymn
  [Tkinter] It it possible to make a help file explorer with tkinter? Clunk_Head 0 2,081 Aug-07-2021, 06:02 PM
Last Post: Clunk_Head
  .get() from generated Entry widgets in tkinter snakes 4 4,412 May-03-2021, 11:26 PM
Last Post: snakes
  [Tkinter] tkinter.Menu – How to make text-variable? Sir 3 5,772 Mar-10-2021, 04:21 PM
Last Post: Sir
  Tkinter Python: How to make sure tkSimpleDialog takes in No value entered rcmanu95 3 2,409 Aug-05-2020, 05:32 AM
Last Post: Yoriz
  How to make button text bold in Tkinter? scratchmyhead 2 12,379 May-16-2020, 02:53 AM
Last Post: scratchmyhead
  Using Tkinter widgets on child window chewy1418 8 7,441 Feb-27-2020, 10:34 PM
Last Post: Marbelous
  Make Label Text background (default color) transparent using tkinter in python barry76 1 24,306 Nov-28-2019, 10:19 AM
Last Post: Larz60+
  Tkinter - Make changes to graph and update it adriancovaci 0 6,685 Apr-08-2019, 09:02 AM
Last Post: adriancovaci
  [Tkinter] Multiple frames with tkinter - How to make them run on fullscreen mode eabs86 3 18,375 Sep-20-2018, 01:27 AM
Last Post: eabs86

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020