473,396 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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
2 1908
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mickel Grönroos | last post by:
Hi, I'm trying to put an Tkinter.Entry of fixed size onto a specific location on a canvas using the place manager. The idea is that one can double-click a rectangle object on a canvas to get an...
1
by: Thomas Nücker | last post by:
Hi! I am creating a dialog-box within my application, using tkinter. The problem is the following: After the dialogbox is started, the main application window comes again to top and the...
2
by: uri bushey | last post by:
Is there an easy way to have a label read from a variable, and update itself when the variable is changed? I have a dialogue that asks for a name, and a label that displays the name that is...
3
by: Matt Hammond | last post by:
Here's a strange one in Tkinter that has me stumped: (I'm running python 2.4 on Suse Linux 9.3 64bit) I'm trying to make a set of Entry widgets with Label widgets to the left of each one, using...
1
by: Michael Yanowitz | last post by:
Hello: Below I have included a stripped down version of the GUI I am working on. It contains 2 dialog boxes - one main and one settings. It has the following problems, probably all related, that...
3
by: H J van Rooyen | last post by:
Hi, Still struggling with my GUI exercise - I have the following lines of code in a routine that is bound at <Key-Returnto an instance of Entry : self.disp.Amount_des = Label(self.disp,...
7
by: Jo | last post by:
Hi, How can i differentiate between static and dynamic allocated objects? For example: void SomeFunction1() { CObject *objectp = new CObject; CObject object;
44
by: bg_ie | last post by:
Hi, I'm in the process of writing some code and noticed a strange problem while doing so. I'm working with PythonWin 210 built for Python 2.5. I noticed the problem for the last py file...
1
by: C Martin | last post by:
What am I doing wrong in this code? The callback doesn't work from the Entry widget. ##start code import Tkinter tk = Tkinter.Tk() var = Tkinter.StringVar() print var._name def cb(name,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.