Placing Tkinter objects in a dictionary

Xiao-Qin Xia xx758 at cam.ac.uk
Thu Nov 7 04:57:04 EST 2002


Adonis wrote:

> I have a loop creating Tkinter objects (an Entry text box) all with the
> same name and placing its instance in a dictionary: i.e:
> 
> for x in range(10):
>     myEntry = Entry(frame)
>     myEntry.grid(row=x, column=0)
> 
>     someDict['%s'%x] = myEntry
> 
> now I have another function which will modify myEntry:
> 
> def someFunc(x, data):
>     someDict[str(x)].config(text=data) # here is my error; the config does
> not work;
>                                        # no error is raised.
> 
> any help is greatly appreciated.
> 
> Adonis

The problem is Entry does use a text config, you need a method to insert 
the data:

def someFunc(x, data):
        e = someDict[str(x)]
        e.delete(0, END)
        e.insert(0, data)

Now it will work.


Cheers,

Xiao-Qin Xia



More information about the Python-list mailing list