简体   繁体   中英

Tk Canvas Usage in Python

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM