TKinter, Entry objects and dynamic naming

Ian Vincent i_vincent at hotmail.com
Tue Sep 13 03:51:47 EDT 2005


I am hoping someone may be able to help.

I am using Python and TKinter to create a GUI program that will 
eventually create an XML file for a project I am working on. Now, the XML 
file contents changes depending on the type of file it represents - so I 
am dynamically creating the TK Entry boxes. The problem is, I want the 
variable assigned to each of these boxes to be dynamically assigned as 
well but I cannot see how to do this (if it is indeed possible).

Example

If the file the XML is to represent is a spreadsheet - I want the first 
entry box to be:

spreadsheetField = StringVar()
value = Entry(root, relief=SUNKEN, justify=LEFT, 
textvariable=spreadsheetField)

however, if the file is a document - I want the first entry box to be:

documentField = StringVar()
value = Entry(root, relief=SUNKEN, justify=LEFT, 
textvariable=documentField)

I have quite a few Entry boxes for each file type (about 10) and a lot of 
filetypes (over 80), so I do not want to have a custom function for each 
filetype if I can help it.

I have looked at using a dictionary but I cannot get my head around how 
to do that either.

If anyone can give me any ideas, I would be very grateful.



More information about the Python-list mailing list