[Tutor] why can use a widget assigned to a variable or just use it on it's own?
timomlists at gmail.com
Mon Jul 2 03:24:44 EDT 2018
Op 02-07-18 om 03:54 schreef Chris Roy-Smith:
> 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)
You still create an instance, but don't assign it to a variable. See
f = Foo() # prints "Instance created"
Foo() # print "Instance created"
Two instances are created, just that the second one isn't accessible.
> any explanation gratefully recieved
> Regards, Chris ROy-Smith
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
More information about the Tutor