0

I've been following a Tkinter Python tutorial on its frame widget.
(Under the subsection Assigning Widgets to Frames With Frame Widgets. Search by that phrase to get there easily.)

frame_a=tk.Frame()    
frame_b=tk.Frame()

label_a=tk.Label(text="I am frame A")   
label_a.master=frame_a    
label_a.pack()   

label_b=tk.Label(text="I am frame B")  
label_b.master=frame_b
label_b.pack()

frame_a.pack()  
frame_b.pack()  

When I ran this code it successfully gave this output.
Consider the last two lines; the tutorial suggested to change their order, and put frame_b.pack() before frame_a.pack() and that will make the phrase 'I am frame B' will come on top, as frame_b is packed first.

However, I get the same output as before. What is am I doing wrong here? (The code runs without errors.)

1
  • 1
    Give your frames a width and height, and a distinctive color. That will make it easier for you to see what is happening. Setting the master attribute like you're doing does absolutely nothing. Commented Aug 27, 2020 at 18:22

1 Answer 1

1

As @Brian commented, label_a.master() does not do anything, so move the label.pack() commands like this:

frame_a=tk.Frame()    
frame_b=tk.Frame()

label_a=tk.Label(text="I am frame A")   

label_b=tk.Label(text="I am frame B")  

label_b.pack()
label_a.pack()#Moved

frame_b.pack()
frame_a.pack()
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.