[Tutor] Saving Entry fields in Tkinter

Michael Lange klappnase at freenet.de
Tue Mar 1 20:52:44 CET 2005


On Tue, 1 Mar 2005 12:52:57 +0100
Ewald Ertl <ewald.ertl at hartter.com> wrote:

> Hi!
> 
> Perhaps this could help you: 
> 
> fileContent=open( "my/file/to/read", "r").readlines()
> 
> for line in fileContent:
> 	print line.strip()   # remove leading and trailing whitspace's incl. \n
> 
> 
> In the loop you could perhaps populate the entry-widgets. 
> 
> HTH  
> 
> Ewald 

Or use the fileinput module:

var_list = []
for line in fileinput.input(filename):
    var = Tkinter.StringVar()
    var.set(line)
    var_list.append(var)

Best regards

Michael

> 
> on Tue, 1 Mar 2005 09:22:06 +0000  Adam Cripps <kabads at gmail.com> wrote :
> ---------------------------------------------------------------------------------------------
> 
> Adam Cripps > I'm writing an application which has rows of Entry fields (created in
> Adam Cripps > a loop - see previous thread; and thanks guys!). All the content of
> Adam Cripps > the Entry fields are accessed through self.contentlist[i].get()
> Adam Cripps > 
> Adam Cripps > Now I'm trying to save the content of those fields in a friendly
> Adam Cripps > format. I've used pickle in the past, but experienced problems with
> Adam Cripps > pickling Tkinter widgets.
> Adam Cripps > 
> Adam Cripps > I'm saving using this method :- 
> Adam Cripps > 
> Adam Cripps > for i in self.contentlist:
> Adam Cripps >     saving = i.get() + "\n"
> Adam Cripps >     f.write(saving)
> Adam Cripps > f.close()
> Adam Cripps > 
> Adam Cripps > which creates a text file with each entry field separated with a "\n". 
> Adam Cripps > 
> Adam Cripps > What would be a good way to open this file and re-populate the entry
> Adam Cripps > fields with the content?  I'm not sure how to parse the text according
> Adam Cripps > to the \n separator.
> Adam Cripps > 
> Adam Cripps > Am I going down the right path here? 
> Adam Cripps > 
> Adam Cripps > TIA
> Adam Cripps > Adam
> 
> 
> ------------------- end ----------------------
> 
> 
> -- 
> Ing. Ewald Ertl         HartterGruppe                   Phone : +43-3352-33085-558
> trinomic Projektmanagement & Informationstechnik GmbH   Fax   : +43-3352-33085-600
> Wiener Straße 41                                        mailto:ewald.ertl at trinomic.com
> A-7400 Oberwart         http://www.trinomic.com         mailto:ewald.ertl at hartter.com
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


More information about the Tutor mailing list