Marc
2004-01-27 01:09:49 UTC
Hi all,
I was using Tkinter.IntVar() to store values from a large list of
parts that I pulled from a list. This is the code to initialize the
instances:
def initVariables(self):
self.e = IntVar()
for part, list in info.masterList.items():
obj = setattr( self.e, part, IntVar() )
That allowed me to save bundles of info without having to create
another large dictionary or list. I was using the variable in entry
boxes to store the amount of parts ordered:
Entry( cscGroup.interior(), width=3, textvariable =
getattr(self.e, part),
text=e.get()).grid(row=x, column=2, padx=4
)
However, I ran into problems when I tried to pickle the instances in
order to recall them later. To fix that problem I created my own
simple data class that allowed me to save the data the same way while
also having the ability to pickle it:
class DataVar:
def __init__(self):
self.data = 0
self.partName = ""
def set(self, value):
self.data = value
def get(self):
return self.data
But I just discovered another problem. It doesn't appear to hold data
the same way. The information appeared global when it was IntVar().
Now when I go outside the class that set up the entry boxes, the
information does not appear to be in DataVar. I print out the info the
following way:
def printValues(self):
for part, list in info.masterList.items():
e = getattr(self.e, part)
print str(part) + " --->" + str( e.get() )
This function is in the same class that initialized the DataVar
variables and also that called the class that setup the window to
enter the amount of parts. When I call that class I pass in the
variable in the following way:
spares = Spares(self.master, self.e)
So obviously there's something about Tkinter that causes the info to
be global. But even though the DataVar class is an independent class,
for some reason the information is not being maintained.
Does anyone have any idea why this is happening and how to fix it?
Thanks ahead of time,
Marc
I was using Tkinter.IntVar() to store values from a large list of
parts that I pulled from a list. This is the code to initialize the
instances:
def initVariables(self):
self.e = IntVar()
for part, list in info.masterList.items():
obj = setattr( self.e, part, IntVar() )
That allowed me to save bundles of info without having to create
another large dictionary or list. I was using the variable in entry
boxes to store the amount of parts ordered:
Entry( cscGroup.interior(), width=3, textvariable =
getattr(self.e, part),
text=e.get()).grid(row=x, column=2, padx=4
)
However, I ran into problems when I tried to pickle the instances in
order to recall them later. To fix that problem I created my own
simple data class that allowed me to save the data the same way while
also having the ability to pickle it:
class DataVar:
def __init__(self):
self.data = 0
self.partName = ""
def set(self, value):
self.data = value
def get(self):
return self.data
But I just discovered another problem. It doesn't appear to hold data
the same way. The information appeared global when it was IntVar().
Now when I go outside the class that set up the entry boxes, the
information does not appear to be in DataVar. I print out the info the
following way:
def printValues(self):
for part, list in info.masterList.items():
e = getattr(self.e, part)
print str(part) + " --->" + str( e.get() )
This function is in the same class that initialized the DataVar
variables and also that called the class that setup the window to
enter the amount of parts. When I call that class I pass in the
variable in the following way:
spares = Spares(self.master, self.e)
So obviously there's something about Tkinter that causes the info to
be global. But even though the DataVar class is an independent class,
for some reason the information is not being maintained.
Does anyone have any idea why this is happening and how to fix it?
Thanks ahead of time,
Marc