Tkinter - winfo_height() always returns 1

50 Views Asked by At

I have a function that gets called by clicking a button called expand_keyword. This function expands a row of a table to show more data. The data is contained in multiple frames called single_cve_frame.

I'm trying to get the height of those frames by using the function winfo_height() but I always get returned the value '1'. I tried retrieving the value after packing the frame and after calling the root's function update_idletasks() but I get the same result. I call the function by accessing the parent of self which is the root. Here is my code:

def expand_keyword(self, frame: ExpandableKeywordCVEsFrame, organized_cves):
        for cve in organized_cves[keyword]['matching_cves']:
            single_cve_frame = ctk.CTkFrame(frame, fg_color = '#E1E1E1')
            ctk.CTkLabel(single_cve_frame,
                         text = cve,
                         text_color = 'black',
                         font = ('Inter', 18)
                         ).place(relx = 0.2, rely = 0.5, relwidth = 0.25, relheight = 1, anchor = 'center')
            
            single_cve_frame.pack(expand = True, fill = 'both')
            print(single_cve_frame.winfo_height())
            self.master.update_idletasks()
            print(single_cve_frame.winfo_height())

Edit: I've noticed that The w_info_height values are returned before the widgets are generated on the gui. This could be the reason they are '1'. Even by setting the height of the frames statically, the values are still 1.

0

There are 0 best solutions below