0

Trying to make a dashboard using excel as backend which displays the data associated to the selected value; approach is simple

select name

click on button select to display

problem: the previous label is not getting overwritten


def display():
    value = combo1.get()
    
    row = df.loc[df["Project Name"] == value]
    projectname = row["Project Name"].values[0]
    srno = row["Sr No"].astype(str).values[0]
    client = row["Client"].values[0]

    label19 = ttkb.Label(Frame2, text="",bootstyle="info")
    label19.grid(row=0, column=1, padx=20, pady=10,columnspan=10)
    label19 = ttkb.Label(Frame2, text=srno,bootstyle="info")
    label19.grid(row=0, column=1, padx=20, pady=10,columnspan=10)
    label20 = ttkb.Label(Frame2, text="",bootstyle="info")
    label20.grid(row=1, column=1, padx=20, pady=10,columnspan=10)
    label20 = ttkb.Label(Frame2, text=client,bootstyle="info")
    label20.grid(row=1, column=1, padx=20, pady=10,columnspan=10)

Button1 = ttkb.Button(Frame, text="Select", bootstyle="success-link",command=display)
Button1.pack(side="left", padx=10)
    

tried several ways, seems to not working according to my code please note I m newbie

Harry
  • 3
  • 3
  • Putting a new widget into an existing grid cell does absolutely nothing to get rid of any previous widget in that cell; it's still there, and if larger than the new widget, will be at least partially visible behind it. This is more than just a cosmetic problem - all of those piled-up widgets are still taking up memory, Tkinter will get slower and slower over time, and eventually crash. Your options are to either delete the old widgets, or create only one set of widgets at startup and simply reconfigure their `text` and other properties to display the new data. – jasonharper Feb 20 '23 at 14:46
  • understood, how can i delete the old widgets before new ones appear; i have tried but nothing works; saw tutorials used grid forget . label destroy but nothing solves – Harry Feb 20 '23 at 14:48
  • The easiest case would be if the widgets were the entire contents of a Frame or Window; you could iterate over them via `.winfo_children()` in order to delete them. If that's not the case, you'd have to save references to each one, in such a way that you can still access them when it comes time to delete them - your current code fails in this regard because your references are all local variables that will vanish as soon as the function exits. – jasonharper Feb 20 '23 at 14:53
  • Why do you have duplicated label19 and label20? – toyota Supra Feb 21 '23 at 15:04
  • was trying a solution from video @toyotaSupra – Harry Feb 27 '23 at 17:31

0 Answers0