Can you pack multiple Tkinter widgets at a time rather than packing them individually? Can you pack multiple Tkinter widgets at a time rather than packing them individually? tkinter tkinter

Can you pack multiple Tkinter widgets at a time rather than packing them individually?


You could use root.children to get all the buttons and labels added to that parent element and then call the pack function for those. children is a dictionary, mapping IDs to actual elements.

root = Tk()label1  = Label(root, text="label1")button1 = Button(root, text="button1")label2  = Label(root, text="label2")button2 = Button(root, text="button2")for c in sorted(root.children):    root.children[c].pack()root.mainloop()

This will pack all those buttons and labels underneath each other, from top to bottom, in the same order as they where added to the parent element (due to sorted). Note, however, that the usefulness of this is rather limited, since normally you'd not just place all your widgets in one column.