0
root=Tk()
#root.geometry('800x500+100+100')
#root.resizable(0,0)
root.title('Lottery Number Generator')
frame_1 = Frame(root).pack(side=TOP)
num1 = IntVar()
num2 = IntVar()
num3 = IntVar()
num4 = IntVar()
num5 = IntVar()
num6 = IntVar()

var=StringVar()
var.set("Lucky Lottery generator")

label = Label(frame_1,textvariable=var,font=('times',24,'bold'),width=26).pack(side=TOP)
label = Label(frame_1,textvariable='',width=32).pack(side=TOP)
#label = Label(frame_1,textvariable='',width=32).pack(side=TOP)


frame_2 = Frame(root).pack(side=TOP)

entry_1 = Entry(frame_2,width=4,font=('arial',30),justify=CENTER,bd=20,insertwidth=1,textvariable=num1).pack(side=LEFT)
entry_2 = Entry(frame_2,width=4,font=('arial',30),justify=CENTER,bd=20,insertwidth=1,textvariable=num2).pack(side=LEFT)
entry_3 = Entry(frame_2,width=4,font=('arial',30),justify=CENTER,bd=20,insertwidth=1,textvariable=num3).pack(side=LEFT)
entry_4 = Entry(frame_2,width=4,font=('arial',30),justify=CENTER,bd=20,insertwidth=1,textvariable=num4).pack(side=LEFT)
entry_5 = Entry(frame_2,width=4,font=('arial',30),justify=CENTER,bd=20,insertwidth=1,textvariable=num5).pack(side=LEFT)
entry_6 = Entry(frame_2,width=4,font=('arial',30),justify=CENTER,bd=20,insertwidth=1,textvariable=num6).pack(side=LEFT)

frame_3 = Frame(frame_2,bg='black').pack(side=BOTTOM)

button =Button(frame_3,bg='green',padx=8,pady=8,font=('times',14,'bold'),width=18,text='Generate Numbers',command=lotto).pack(side=TOP)

I have created 3 frames and I have set 'side=top'. The frames contain labels, entries, buttons, etc. However, my 3rd frame is not shown correctly; it is shown right to frame 2.

Please help!

David Duran
  • 1,786
  • 1
  • 25
  • 36
onemanarmy
  • 93
  • 10

1 Answers1

1

Your problems can be solved by fixing the following:

  • You are creating the frame 3 inside frame 2. It should be created on the root:

frame_3 = Frame(root,bg='black')

  • You should separate the design part from the '.pack' one. So put all the '.packs' (at least for the frames) at the end, like this:
# Place all the frames
frame_1.pack(side=TOP)
frame_2.pack(side=TOP)
frame_3.pack(side=TOP)

With these changes, the button appears at the bottom as you want. It is not necessary to pack the last frame with 'side=BOTTOM', since you have already packed the two previous frames before.

Please, in the future provide a Minimal Working Example (you were missing the root.mainloop() and the command of the button was not defined).

David Duran
  • 1,786
  • 1
  • 25
  • 36
  • ya sure next time i will ensure req code is present and 1 more doubt i have to clear while creating 3 frames where the third frame will be placed ?right of frame 2 ?or below frame 2? – onemanarmy Mar 01 '17 at 12:46
  • I am not sure if I understand your doubt... I mean you can place the frame where you need. To clear a frame, it is not necessary to delete the frame itself: you can destroy the children of the frame. See http://stackoverflow.com/a/15995920/2726773 – David Duran Mar 01 '17 at 13:13
  • actually i need to know for ex-if i had 3 frames,how the 3 frames will be placed in the root window(all 3 are paced at side=TOP) – onemanarmy Mar 02 '17 at 07:02
  • The frames are placed relative to each other. So the first frame you place will be the one at the top of the window, while the last will be at the bottom though you are using 'side=TOP' for it. – David Duran Mar 02 '17 at 07:18
  • actually what i found out is while creating first frame1 it occupies whole root,then while creating frame 2 it occupies bottom,and finally when i create frame 3 i occupies right of frame 2[hint --> all frames were packed,side=TOP] this is what i found out man – onemanarmy Mar 02 '17 at 10:49
  • If you do what I tell you in my answer, the three frames are created in order from top to bottom. – David Duran Mar 02 '17 at 12:01