widget confusion

Will Stuyvesant hwlgw at hotmail.com
Mon Aug 5 10:29:43 CEST 2002


ypoi at spray.se (DR) wrote in message: 
> Here's a problem I can't figure out:
> 
>     self.b1=Button(text="Create new entry", command=self.newEntry
>     self.b1.grid()
> def newEntry(self)
>     self.entryX=Entry()
>     self.entryX.grid()
> 
> Now every time i press the "Create new entry" button a new entry will
> be created in the frame. But when i perform an action on entryX (for
> example the .get() method) i only access the most recently created
> entry. How can i take control of the other ones?

Every time you do "self.entryX=..." you overwrite the old value of
self.entryX!

If you want to 'remember' old entryX values you need something like:
def newEntry(self):
    entry = Entry()
    entry.grid()
    self.entries.append(entry)
Now the Entries are in self.entries in the order you created them.
This assumes you have self.entries initialised in your __init__ like
"self.entries = []", but you could also choose a dict for self.entries
if you want to name each entry and change newEntry accordingly.

'''
Isn't it strange that the same people that laugh at gypsy fortune
tellers take economists seriously?
'''



More information about the Python-list mailing list