PyRoss
PyRoss

Reputation: 129

(Python 3.4 Tkinter) Frame issue

When I run this code:

from tkinter import *
root = Tk()

fr = Frame(root, width=50, height=50).pack()
b = Button(fr, text='Click').pack()

root.mainloop()

button 'b' is outside the frame 'fr', acting as if i wrote root instead of fr in b = Button(fr, ....

Upvotes: 1

Views: 130

Answers (1)

Marcin
Marcin

Reputation: 238877

You should execute pack on the object returned from Frame and Button.

fr = Frame(root, width=50, height=50)
fr.pack()
b = Button(fr, text='Click')
b.pack()

Otherwise, your fr and b are None, i.e. they take values returned by pack() which is None.

Upvotes: 3

Related Questions