[Tutor] Help with class in class
leamhall at gmail.com
Sun Sep 9 21:12:48 CEST 2012
On Sun, Sep 9, 2012 at 12:12 PM, Peter Otten <__peter__ at web.de> wrote:
> the above will no longer complain about a missing attribute.
> > root = Tk()
> > project = ch8_Project(master=root)
> > project.mainloop()
> Another problem that caught my attention:
> > self.green = Button(root, text="Green",
> The command argument is supposed to be a function; you are instead
> the result of a method call (which is None in this case, but as a side
> effect will set the color to green immediately. The simplest fix is to
> define a helper function that takes no arguments
> def change_to_green():
> self.green = Button(root, text="Green", command=change_to_green)
> If you already know about lambda you can try to rewrite this using that.
Peter, thank you for helping me understand the scope issue I was missing! I
knew it was something like that but forget that omitting "this." meant the
variables were limited in scope to that method.
I have seen lamba but do not understand it. The project requires four
buttons, each one turns the same text a different color. The class is also
Python 3 based. :)
Mind on a Mission <http://leamhall.blogspot.com/>
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor