[Tutor] Tkinter layout problem continued
Abel Daniel
abli@freemail.hu
Mon Jul 14 12:43:03 2003
> #
> from Tkinter import *
> import Pmw
> parent = Tk()
> parent.geometry("400x200+300+300")
>
> button_frame = Pmw.Group(parent, tag_text='Actions')
> startButt = Button(button_frame.interior(), padx=20,text="Start",
> bg='Green', command=parent.destroy)
> exitButt = Button(button_frame.interior(), padx=20,text="Exit", bg='red',
> command=parent.destroy)
> pauseButt = Button(button_frame.interior(), padx=20,text="Pause",
> bg='orange', command=parent.destroy)
>
> startButt.grid(row=0,column=0, sticky=W)
> exitButt.grid(row=0, column=1, sticky=W)
> pauseButt.grid(row=0, column=2, sticky=W)
> button_frame.grid(row=2, column=0, sticky=W+E) #Why doesn't the frame fill
> the window?
parent.grid_columnconfigure(0, weight=1)
>
> parent.mainloop()
> #
Adding that line makes it work for me. The button_frame expands as
expected, revealing that the buttons inside the button_frame have the
same problem. So if you want the buttons to expand, too, you need:
button_frame.interior().grid_columnconfigure(0, weight=1)
button_frame.interior().grid_columnconfigure(1, weight=1)
button_frame.interior().grid_columnconfigure(2, weight=1)
Or, instead of all this grid_columnconfigure-ing you can simply use the
pack geometry manager:
#
from Tkinter import *
import Pmw
parent = Tk()
parent.geometry("400x200+300+300")
button_frame = Pmw.Group(parent, tag_text='Actions')
startButt = Button(button_frame.interior(), padx=20,text="Start",
bg='Green', command=parent.destroy)
exitButt = Button(button_frame.interior(), padx=20,text="Exit",
bg='red', command=parent.destroy)
pauseButt = Button(button_frame.interior(), padx=20,text="Pause",
bg='orange', command=parent.destroy)
startButt.pack(fill=X, side=LEFT, expand=1)
exitButt.pack(fill=X, side=LEFT, expand=1)
pauseButt.pack(fill=X, side=LEFT, expand=1)
button_frame.pack(fill=X, expand=1)
parent.mainloop()
#
And I think the padx=20 options aren't needed.
Abel Daniel