On Sun, Sep 9, 2012 at 12:12 PM, Peter Otten <[email protected]> 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",
> command=self.change_text_color("green"))
>
>
> The command argument is supposed to be a function; you are instead
> assigning
> 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.change_text_color("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. :)
Leam
--
Mind on a Mission <http://leamhall.blogspot.com/>
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor