onemanarmy
onemanarmy

Reputation: 93

Tkinter frames are not generated properly window

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!

Upvotes: 0

Views: 45

Answers (1)

David Duran
David Duran

Reputation: 1826

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).

Upvotes: 1

Related Questions