[Tkinter-discuss] Re: Storing structured, 'widget-specific-data', then loading it back in la ter

Martin Franklin mfranklin1 at gatwick.westerngeco.slb.com
Tue Oct 5 13:14:42 CEST 2004

On Sun, 3 Oct 2004 03:32:06 GMT, Chris Nethery <clnethery at juno.com> wrote:

> Hello everyone!
> I have been working on the following for a while and just cannot get it  
> to work correctly, so I am hoping that someone could offer some advice.
> I am trying to create a group of (re-usable) methods that take user  
> input data and store it for future reference, then reload it later to  
> the same widget where it was originally created.  I wrote the following  
> program to try to get the process working.  The first button is supposed  
> to store the data, and the second button is meant to plug the data back  
> into the widget.  I seem to be having difficulty plugging the data back  
> into the widget, because I cannot identify it(the widget) properly.  Any  
> thoughts?

<snipped code>


This does not in anyway answer you questions.... but it may give you
some ideas :-)

 from Tkinter import *
import Pmw

class PickleMixin:
     def __init__(self):
         self.widgets = {}
         self.storage = {}

     def store(self):
         # could add a pickle to file call here
         for name, widget in self.widgets.items():
             self.storage[name] = widget.getData()

     def restore(self):
         # could add a pickle from file call here
         for name, widget in self.widgets.items():

class MyWidget(Frame, PickleMixin):
     def __init__(self, parent):
         Frame.__init__(self, parent)

         self.list = Pmw.ScrolledListBox(self)
         self.list.setData = self.setList
         self.list.getData = self.getList

         self.entry = Pmw.EntryField(self)
         self.entry.setData = self.setEntry
         self.entry.getData = self.getEntry

         self.widgets["list"] = self.list
         self.widgets["entry"] = self.entry

         self.list.setlist([1, 2, 3, 4, 5, 6, 7])
         self.entry.setentry("yada yada")

     def getList(self):
         return self.list.get()

     def setList(self, data):

     def getEntry(self):
         return self.entry.get()

     def setEntry(self, data):

if __name__=="__main__":

     mw = MyWidget(root)

     b = Button(root, command=mw.store, text="Store Data")

     b = Button(root, command=mw.restore, text="Re-Store Data")



Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

More information about the Tkinter-discuss mailing list