Dynamically creating forms

rainer2207 at my-deja.com rainer2207 at my-deja.com
Sun Sep 12 21:29:46 EDT 1999


How would someone go about dynamically creating forms? Basically I'm
reading from a file which specfies the labels and entry widgets. Since
I don't know what labels are required I can just create the labels and
entry areas, I have to do it dynamically. I currently have:

class NamedEntry:

	def __init__(self, master, text):

		self.Frame = Frame(master)
		self.Frame.pack(side='top', fill='x')

		self.label = Label(self.Frame, anchor='w', width=15,
text=text)
		self.label.pack(side='left')

		self.entry = Entry(self.Frame)
		self.entry.pack(side='left', expand=1, fill='x')

	def get_value(self):

		text = self.entry.get()
		self.entry.delete('0', 'end')
		return text

	def set_value(self, value):

		self.entry.delete('0', 'end')
		self.entry.insert('end', value)

I have thought about putting the instance names in a list:
eg

L.append("instancename")

and then doing

for l in L:
    l = NamedEntry(somewindow, somelabel)

but I can't use the get_value methods in the class because Python thinks
the instance name is just a string. Does anyone have any ideas on what
I could do or maybe another way od dynamically creating forms?

Any thoughts would be appreciated. Thanks.

Rainer


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




More information about the Python-list mailing list