Kevin Soler Carracedo
Kevin Soler Carracedo

Reputation: 21

Tkinter packing entrys at different column than button

I am using a simple code:

frame_bottom = Frame(root)
frame_bottom.pack(fill='x')

button1 = Button(frame_bottom, text = 'One', command =  visualize)
button2 = Button(frame_bottom, text = 'Two', state = DISABLED)
label_rango1 = Label(frame_bottom, text = 'Sigma value:')
e_sigma = Entry(root, borderwidth = 2)

label_rango1.pack(side='left',  expand=True)
e_sigma.pack(side='left')
button1.pack(side='left',  expand=True)
button2.pack(side='left', expand=True)  

Howerer, despite of using side='left', the entry is placed below the rest of the buttons. Any idea on how to pack everything in the same line?

Thanks!

Upvotes: 0

Views: 83

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 385830

The reason is due to the fact that button1 and button2 are children of frame_bottom, but e_sigma is a child of root. You pack frame_bottom before e_sigma and don't provide any options, so frame_bottom is being added to the top of the root window (well, top of the available space, which matters if you've already packed other widgets in the root window). When you pack e_sigma it must go in the remaining space which by definition is below frame_bottom.

Put another way, frame_bottom and e_sigma are both children of root. frame_bottom is packed first and e_sigma is packed second, both with default options. Therefore, frame_bottom will appear above e_sigma.

If you want the entry to be to the right of the buttons, it needs to have the same parent as the buttons.

Upvotes: 1

Related Questions