Using Tkinter i have created 5 frames, each containing
- frame0 -
label,Entry boxand abutton(Enter) - frame1 -
labelandlist boxat the left side - frame2 -
2 buttons(select & unselect)at the center - frame3 -
labelandlistboxat the right side frame4 -
2 buttons(done & clear)---------------------------------------- | frame0 | ---------------------------------------- | | | | | frame1 | frame2 | frame3 | | | | | ---------------------------------------- | frame4 | ----------------------------------------
This is my code:
from Tkinter import *
def toplevelwin():
def clear():
return
def select():
return
def unselect():
return
def done():
return
def enter():
return
window = Toplevel()
frame0 = Frame(window)
frame0.grid(row=0, column=0, sticky=W, padx=5, pady=5, columnspan=2)
frame0.grid_columnconfigure(1,weight=2)
lblentry = Label(frame0, text="Entery Box:")
lblentry.grid(row=0, column=0, sticky=W)
entrybx = Entry(frame0)
entrybx.grid(row=1,column=0,sticky=N+S+E+W, columnspan=2)
entrybt = Button(frame0, text=' Enter ', command=enter)
entrybt.grid(row=1,column=2,sticky=N+W, padx=3)
frame1 = Frame(window)
frame1.grid(row=1, column=0, sticky=E+W, padx=5, pady=5)
lblshow_lst = Label(frame1, text="List Box 1:")
lblshow_lst.grid(row=0,sticky=W)
show_lst = Listbox(frame1)
show_lst.grid(row=1,sticky=W)
frame2 = Frame(window)
frame2.grid(row=1, column=1, sticky=W)
frame2.grid_columnconfigure(1,weight=1)
selbtn = Button(frame2, text='Select', command=select)
selbtn.grid(row=0, padx=5, sticky=E+W)
selbtn.grid_columnconfigure(1,weight=1)
uselbtn = Button(frame2, text='Unselect', command=unselect)
uselbtn.grid(row=1, padx=5, sticky=E+W)
uselbtn.grid_columnconfigure(1,weight=1)
frame3 = Frame(window)
frame3.grid(row=1, column=2, sticky=W, padx=5, pady=5)
lblsel_lst = Label(frame3, text="List Box 2:")
lblsel_lst.grid(row=0,sticky=W)
sel_lst = Listbox(frame3)
sel_lst.grid(row=1, column=0, sticky=W)
frame4 = Frame(window)
frame4.grid(row=2, column=0, sticky=E, padx=5, pady=5)
Button(frame4, text=' Done ', command=done).grid(row=0, column=0, padx=7 ,pady=2)
Button(frame4, text='Clear', command=clear).grid(row=0,column=1, padx=7,pady=2)
window.wait_window(window)
root = Tk()
toplevelwin()
root.mainloop()
And this is how my window looks now:
My Question is:
- How do i expand
frame0uptillframe3. ie, i want theentry boxto extend till frame3's end having thebutton(enter)to its right side as it is. - And i want the
bottom frame'sbutton(done and clear) to be placed on the right side of the window
Tries:
i tried to increase the size of the entry widget, which in turn pushed frame2 and frame3 to the right side.
used
sticky=N+S+W+E, which pushed it to the center of the windowalso did tried
sticky=Wfor the bottom frame containing 2 buttons. They moved to the center but not right


packwhich might make things easier. Are you interested in that solution, or are you specifically asking about how to fix problems with grid? ie: is the question "how do I get the layout I want" or is it "what am I doing wrong with grid"? - Bryan Oakleygridwould be a better option. And more over i wanted to "how can i get the layout what i wanted" usinggrid. Also if you come across wrong or weird code lines, plz do rectify me - arvindh