1

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

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.