newbie with major "lambda" problem (perhaps a scope problem as well)
John Roth
johnroth at ameritech.net
Wed Jun 27 10:21:38 EDT 2001
"Joe Potter" <jm7potter at hotmail.com> wrote in message
news:gkkjjts1msjq3ps19qs1aobi6m06jtscpc at 4ax.com...
> On Tue, 26 Jun 2001 22:00:52 -0700, "John Roth" <johnroth at ameritech.net>
wrote:
>
> >
> >"Joe Potter" <jm7potter at hotmail.com> wrote in message
> >news:n8dhjt8qmel0ajjae7tv9gmjf60c39qag5 at 4ax.com...
> >> On Tue, 26 Jun 2001 16:09:06 GMT, "Rainer Deyke" <root at rainerdeyke.com>
> >wrote:
> >>
> >> >"Joe Potter" <jm7potter at hotmail.com> wrote in message
> >> >news:j5ahjtkfmf32lkqtap0q1u6rig385d7b5i at 4ax.com...
> >> >> # the "button" below works like a champ !!
> >> >> #Button(root, text='Fetch',
> >> >> #command=(lambda v=vars: fetch(v))).pack(side=LEFT)
> >> >>
> >> >> # the "button" below does not do anything ??????
> >> >> Button(root, text='Fetch',
command=(fetch(vars))).pack(side=LEFT)
> >> >
>
> <snip>
>
>
> >
> >Then in effect I'm building an unnamed function definition, and assigning
> >default
> >values to the two parameters. Those default values will travel with the
> >definition,
> >so when Tkinter calls it later, they will be availible to the actual
> >execution.
> >
> >The call of foo(a,b) in the definition above is part of the definition -
it
> >won't be
> >executed until the function object is executed later.
> >
>
> Thanks John,
>
> I think I see it. If I can get a look at the solution to the code example
that I used
> in my reply to Chris Barker --- I'll have it made.
>
> Perhaps you can take a look at that example also?
>
> Thanks again.
>
> Regards, Joe
You don't need to create a frame at all - the classes I write just go right
ahead
and start loading widgets into the parent widget, which is passed in as a
parameter.
Setting up your class as a frame is somewhat better for code reuse, but it
really depends on what you want to do with it If it's a one-shot, a frame is
redundant. If it's a group of controls you're likely to want to use
somewhere
else, then putting it in a frame makes it much more portable.
The following snippet shows one I wrote recently:
class ADataEntryUI:
def __init__(self, parent, frame):
self.ParentClass = parent
self.DateType = "Gregorian"
self._DateVar = StringVar()
self._DateError = ""
self.TimeType = "AM"
self._TimeVar = StringVar()
self._TimeError = ""
As you can see, it doesn't subclass anything!
John Roth
More information about the Python-list
mailing list