[Tutor] why can use a widget assigned to a variable or just use it on it's own?

Chris Roy-Smith chris_roysmith at internode.on.net
Sun Jul 1 21:54:08 EDT 2018


I'm trying to understand working with objects.

If I have grasped things correctly a widget is an object. So why can I 
assign the widget, or use it stand alone? See sample code below


from tkinter import *

# as I understand it this will create an instance of the button widget 
called b1
b1=Button(main, text='instantce', command= lambda b='goodbye' : 
print(b)).grid(row=1, column=0)

# but here I haven't made an instance, but all seems well
Button(main, text='test1', command=lambda a='hello' 
:print(a)).grid(row=0, column=0)



any explanation gratefully recieved

Regards, Chris ROy-Smith

More information about the Tutor mailing list