0

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)
Oasis
  • 1
  • 1
  • From the pictures, the platform seems to be Windows 10. But `win.attributes("-zoomed")` will raise exception because `-zoomed` is not a supported attribute in Windows. Removing that checking and adding missing parts to make the code runnable, I cannot reproduce the problem in my Windows 10 box. – acw1668 Dec 03 '20 at 08:50
  • Hi, thank you for your reply. I removed the line and it worked ! However, the window now would not automatically resize to accommodate the height of the new table each time it refreshes. What do you suggest I do to make the window change size automatically to house widget produced? Many thanks!!! – Oasis Dec 03 '20 at 09:02
  • I think that you have a line like `win.geometry(...)` at the very beginning of the script. Remove that line. – acw1668 Dec 03 '20 at 09:05
  • no, I didnt set the geometry with any line of code like that :'( – Oasis Dec 03 '20 at 09:22
  • Then you need to post the code how to layout the frames initially. – acw1668 Dec 03 '20 at 09:28

0 Answers0