Tkinter Python: Residue Text from previous call after refreshing widgets in frame

61 Views Asked by At

I am trying to build an organized list for the "last-seen-time" of all of my sensors in the corresponding project with Python Tkinter.

The bottom frame (whatever that is under the two list box), is suppose to refresh each time the "SEND TO CHECK" button is clicked.

It did alright when the window is in full-screen mode. However, when there isn't enough space for the window to display the bottom frame, on the first click, it displayed only part of the text label and resized the window (Please see the attached image). All widgets placed in the bottom frame only successfully appear on the second click.

This problem alternately appear at each click.

first click second click

I wonder why is this happening. Thanks in advance for your help !!

below is the code that gets called when the button is hit.

def check_instruments(exist_instruments):

global tablelabel
global timelabel
global bottom_tableFrame
global bottomtop_Frame
global bottombottom_Frame
global now

tablelabel.destroy()
timelabel.destroy()
bottom_tableFrame.destroy()
bottomtop_Frame.destroy()
bottombottom_Frame.destroy()


all_items = instrument_menu.get(0, END) 
sel_idx = instrument_menu.curselection() 
sel_list = [all_items[item] for item in sel_idx]

if len(sel_list) <=20:

    sel_instrument_info_list=[]

    for sel in sel_list:
        for instrument in exist_instruments:
            if sel == instrument.name:
                sel_instrument_info_list.append(instrument)

    bottom_tableFrame = Frame(win)
    bottomtop_Frame = Frame(bottom_tableFrame)
    bottombottom_Frame = Frame(bottom_tableFrame)

    tablelabel = Label(bottomtop_Frame, text="Instrument Last Seen Information", pady=5)   
    tablelabel.pack()
    timelabel = Label(bottomtop_Frame, text="Time Compared: " + str(now), font='Helvetica 9', padx=30, fg="grey")   
    timelabel.pack(side=RIGHT)

    bottombottom_Frame.columnconfigure((0,2), weight=1)

    for i in range(len(sel_instrument_info_list)): 
        for j in range(3): 

            if j == 0:
                current_entry = Label(bottombottom_Frame, bg = "white", text=sel_instrument_info_list[i].name, font='Helvetica 12 bold')   
                current_entry.grid(row=i, column=j,sticky="EW")

                if sel_instrument_info_list[i].overtime == True:
                    current_entry.config(fg= "red" )

            elif j==1:
                current_entry = Label(bottombottom_Frame, bg = "white", text=sel_instrument_info_list[i].id)   
                current_entry.grid(row=i, column=j,sticky="EW")

            elif j==2:
                current_entry = Label(bottombottom_Frame, bg = "white", text=sel_instrument_info_list[i].lastseentime)   
                current_entry.grid(row=i, column=j,sticky="EW")

    if win.attributes("-zoomed") ==0:
        win.geometry("")   

    bottom_tableFrame.pack(fill=BOTH, expand= 1)
    bottomtop_Frame.pack(fill=X)

    bottombottom_Frame.pack(fill=BOTH, padx=30, pady=20)

And the labels and the frames are declared at the very beginning of the script as following:

bottomtop_Frame = Frame(bottom_tableFrame)
bottombottom_Frame = Frame(bottom_tableFrame)

tablelabel=Label(bottomtop_Frame)
timelabel=Label(bottomtop_Frame)
0

There are 0 best solutions below