0

There is a post of this code, posted by mgilson, that I don't understand. All up to the reference to big_widget makes sense. But, what does the reference to big_widget contribute? The particular post is here. I am trying to refine my code and, I think, use the Frame object. But, the reference to Canvas threw me. I tried to comment but I need 50+ reputation to do so. Not there yet.

import Tkinter as Tk
root = Tk.Tk()
f = Tk.Frame(root)
f.grid(row=0,column=0)
#place buttons on the *frame*
b1 = Tk.Button(f,text="Button1")
b1.grid(row=0,column=0)
b2 = Tk.Button(f,text="Button2")
b2.grid(row=0,column=1)

big_widget = Tk.Canvas(root)
big_widget.grid(row=1,column=0)  #don't need columnspan any more.
0

1 Answer 1

1

big_widget = Tk.Canvas(root) --> A Canvas object is initialized, anchored to root and assigned to big_widget

The next line places the canvas (big_widget) at row=1 column=0 on the grid

(in the same way, a frame (f) was previously initialized and placed at row=0 column=0 on the grid inside root)

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

3 Comments

Yes, I understand what big_widget is. What I don't understand is how it relates to the Tk.Frame object. What purpose does it serve being created when the buttons were created on the previously created Frame?
It really doesn't relate to the f frame, outside of the fact that it is in root and placed alongside of it. big_widget can be used to draw or hold other widgets like any canvas widget... f can be used to hold other widgets as well (buttons, etc...) - Don't overthink this, you have a root with two widgets, a frame and a canvas; they have different properties that you can use the way you like. :) Of course, you can have them interact, but you don't have to.
TNX for the response. "It really doesn't relate"... is what I thought. In other words, those two snippets of code could be deleted and not have any effect on the answer to the original question posted. That is what I thought. Again, TNX for your comments -- much appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.