Hi everybody.

I have problem with .pack() and .grid().

I have to use this line:

    mywin.pack(fill=BOTH, expand=YES)

I have used .grid every where on my file but now here i have copied a pice of code from some where and have pasted to my file, as you see it has used .pack().
I can't change all .grid() to .pack() because it's difficult for me to use .pack() when i want to set for example the place and direction of buttons, so i use .grid() options like row and column.

And if i change that line, that .pack() to .grid(), it doesn't work.
So what should i do?

(Thats the reason i don't like Tkinter at all, it's not friendly.)

Another question. (for using .pack())

I want a Label to be on the top, then an Entry box under the Label and then 3 Buttons under the Ebtry box. (3 Buttons are placed side by side).

How can i do that with using .pack()?
I have used "side = LEFT" for all of them, it put 3 Buttons side wich is ok but the Label and Entry box and 3 Buttons are all placed side by side in one line!

With using .grid() i could use row and culomn and set them but just because of the first question i have asked above, i can't use .grid() and have to use .pack().
If the first question get solved, i could use .grid() options for placing Label and Entry box and Buttons.

Thou shalt not mix grid() and pack() layout managers!

To create the layout you want use frames ...

''' tk_frame_pack101.py
use Tkinter frames for different pack() layouts
'''

# for Python3 change Tkinter to tkinter
import Tkinter as tk

root = tk.Tk()

frame1 = tk.Frame()
frame2 = tk.Frame()
frame1.pack(side='top')  # side='top' is default
frame2.pack(side='top')

# these widgets go into frame1
label = tk.Label(frame1, text="Enter your name:")
entry = tk.Entry(frame1)
label.pack(side='top')
entry.pack(side='top')

# these widgets go into frame2
btn1 = tk.Button(frame2, text='button1')
btn2 = tk.Button(frame2, text='button2')
btn3 = tk.Button(frame2, text='button3')
btn1.pack(side='left')
btn2.pack(side='left')
btn3.pack(side='left')


root.mainloop()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.