Tkinter Python: остаточный текст из предыдущего вызова после обновления виджетов во фрейме

Я пытаюсь создать организованный список всех моих датчиков на "последний раз" в соответствующем проекте с Python Tkinter.

Нижний фрейм (то, что находится под полем с двумя списками), должен обновляться каждый раз, когда нажимается кнопка "ОТПРАВИТЬ ДЛЯ ПРОВЕРКИ".

Все нормально, когда окно находится в полноэкранном режиме. Однако, когда в окне недостаточно места для отображения нижней рамки, при первом щелчке отображается только часть текстовой метки и изменяется размер окна (см. Прикрепленное изображение). Все виджеты, помещенные в нижнюю рамку, успешно появляются только при втором щелчке.

Эта проблема попеременно появляется при каждом нажатии.

первый щелчок второй щелчок

Интересно, почему это происходит? Заранее спасибо за помощь!!

ниже приведен код, который вызывается при нажатии кнопки.

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)

А метки и рамки объявляются в самом начале скрипта следующим образом:

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

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

0 ответов

Другие вопросы по тегам