winfo_width() returns 1 even after using pack() winfo_width() returns 1 even after using pack() tkinter tkinter

winfo_width() returns 1 even after using pack()


You need to update_idletasks:

Calls all pending idle tasks, without processing any other events. This can be used to carry out geometry management and redraw widgets if necessary, without calling any callbacks.

frame.pack()root.update_idletasks() print(frame.winfo_width(), frame.winfo_height())