Checkboxes and Tortured Logic

Marc mnations at airmail.net
Mon Mar 18 18:38:39 EST 2002


I know there's got to be a better way to do this than the way that I
found. But the only way I've been able to succesfully retrieve a value
from a checkbox (using the scant documentation I've been able to find)
looks something like this:

self.modVar = StringVar()

		self.testModules = [
			('EQPT Provisioning Test Cases', 0, 0, NORMAL),
			('OCN Provisioning Test Case', 1, 0, NORMAL),
			('STS Provisioning Test Case', 2, 0, NORMAL)]
		
		for module, row, col, status in self.testModules:
				setattr( self.modVar, module, StringVar() )
				self.modButton = Checkbutton(modFrame, text=module, state=status,
anchor=W,
					variable = getattr( self.modVar, module)).grid(row=row, col=col,
sticky=W)

...
def ocnRun(self):
        #while self.ok:
	    for module, row, col, status in self.gui.testModules:
		    print "The module is=", module
		    a = getattr(self.gui.modVar, module)
		    print "The value is=", a
		    #print "The variable is=", self.modButton.variable
		    #print "The value is=", self.gui.modVar.get()
		    print "The value is=", a.get()
	    self.gui.slot = self.gui.list.curselection()
            #printAll( self.gui.ipaddr.get(), self.gui.var.get(),
self.gui.list.get(self.gui.slot) )
...

ocnRun is called from the main Gui GO button which starts up a
separate thread. The first snippet is in one class and the second
snippet is in another. But the only way I've been able to see any
value is to assign the getattr() result (which is an object of type
IntVar) to a variable and then use that variable with the get()
function. It doesn't work when I combine the two functions into the
same line which is confusing.

Also, I haven't found a way to get an "OFF" value. The only values
that are returned are the "ON" values. Default ON is the value one,
and I can get that value, plus manipulate it using the "onvalue"
option. Default for OFF is '0', but that does not come through. Plus,
I can't manipulate the default value using the "offvalue" option.

Basically I just need to pass the on and off values through to the
other class and have access to the result. Is there an easier way to
do this.

Thanks,
Marc



More information about the Python-list mailing list