Thus spoketh "守株待兔" <[hidden email]>
unto us on Thu, 25 Aug 2011 11:34:04 +0800:
> here is my code ,it can run ,i want to make it simpler,
> to change three sentences to one,
> xb =Button(root, text='Fetch')
> xb.bind("<Button-1>", partial(fetch, entries=ents))
If you want to make your code simpler, I suggest a different approach.
Your problem appears to be the way arguments are passed to the fetch()
callback. It would be much easier to handle if you did not have to pass
the list of Entry widgets to the callback, then your fetch() function
could look like:
With this trick you can use the same callback as a Button command and as
a callback with bind() without any additional headaches.
The entry list could be stored globally or (better) you create a class
based on a Tkinter.Frame that contains all the Entries and make the fetch
() callback a class method.
A simple example on how to create a custom subclass of Frame can be found