467,130 Members | 1,313 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,130 developers. It's quick & easy.

TKinter, Entry objects and dynamic naming

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.
Sep 13 '05 #1
  • viewed: 1647
Share:
2 Replies
On 13 Sep 2005 08:51:47 +0100, Ian Vincent <i_*******@hotmail.com> wrote:
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.
Your requirements are not very precise here. What do represent the entry fields? How do you build them? Are they always strings or can they be integers, or floats, or anything else? Do you have only entry fields or other widgets as well (check buttons, radio buttons, ...)? How do you know the format of the dialog you build?
I have looked at using a dictionary but I cannot get my head around how
to do that either.


This is the way I would go, but without answering the questions above, I won't be able to give you much advice. Supposing you have only entry fields accepting strings, a mapping file type -> field name -> StringVar may be a good solution.

HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17;8(%,5.Z65\'*9--56l7+-'])"
Sep 13 '05 #2
Ian Vincent <i_*******@hotmail.com> wrote in
news:Xn********************************@10.15.188. 42:

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


I have tried this now but the Entry field just does not seem to work:

def add_variable(self, root, varname):
Label(root, text=varname + ': ').grid(row=self.row, column=0,
sticky=E)
self.properties[varname] = StringVar()
value = Entry(root, relief=SUNKEN, justify=LEFT,
textvariable=self.properties[varname])
value.grid(row=self.row, column=1, sticky=E+W)
self.row = self.row + 1
return value
Confused. :-(
Sep 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Mickel Grönroos | last post: by
1 post views Thread by Thomas Nücker | last post: by
2 posts views Thread by uri bushey | last post: by
3 posts views Thread by Matt Hammond | last post: by
1 post views Thread by Michael Yanowitz | last post: by
3 posts views Thread by H J van Rooyen | last post: by
44 posts views Thread by bg_ie@yahoo.com | last post: by
1 post views Thread by C Martin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.