[Tutor] Checkbuttons Variables PY_VAR

Pooja Bhalode poojabhalode11 at gmail.com
Sun Feb 26 22:06:36 EST 2017


Hi,

The following code creates a list of checkboxes (each associated with
different variables) for the user to select from, after having selected the
ones that user wants, I am trying to add the selected variables to another
list so that the selected variables can be accessed later in the code.
However, when I try appending to the new list, it gets appended as PY_VAR
instead of the variable name associated.
Can someone please let me know where I am going wrong. I would really
appreciate it.
Thank you

Pooja
Code given below:

keqparam = IntVar()
delHrxnparam = IntVar()
kfparam = IntVar()
Afparam = IntVar()
ksimparam = IntVar()
Aparam = IntVar()
RAparam = IntVar()
RCparam = IntVar()

total_number_parameters = IntVar()
selectedparam = []
checkboxVars = [keqparam, delHrxnparam, kfparam, Afparam, ksimparam,
Aparam, RAparam, RCparam]

def EstimateParameters():
print "EstimateParameters"
paramroot = Toplevel(root)
paramroot.title("Selection of Parameters to be estimated")
def SelectAll():
for var in checkboxVars:
var.set(1)
def DeselectAll():
for var in checkboxVars:
var.set(0)

Button(paramroot, text = "Select all", command = SelectAll).grid(row = 0,
column = 2, sticky = W)
Button(paramroot, text = "Deselect all", command = DeselectAll).grid(row =
0, column = 3, sticky = W)
Label(paramroot, text = "Select all the parameters to be estimated:
").grid(row = 0, column = 0, sticky = W)
sticklabel = Label(paramroot, text = "1. Reversible reaction001")
sticklabel.grid(row = 1, column = 0, sticky = W)
Label(paramroot, text = u"\t A + B \u21cc D").grid(row = 3, column = 0,
sticky = W)
Checkbutton(paramroot, text = "K_eq", variable = keqparam).grid(row = 2,
column = 1, sticky = W)
Checkbutton(paramroot, text = u"\u0394Hrxn", variable =
delHrxnparam).grid(row = 3, column = 1, sticky = W)
Checkbutton(paramroot, text = "K_f", variable = kfparam).grid(row = 4,
column = 1, sticky = W)
Checkbutton(paramroot, text = "Eact_f", variable = Afparam).grid(row = 5,
column = 1, sticky = W)

sticklabel = Label(paramroot, text = "2. Simple reaction001")
sticklabel.grid(row = 10, column = 0, sticky = W)
Label(paramroot, text = u"\t A + C \u2192 E").grid(row = 12, column = 0,
sticky = W)
Checkbutton(paramroot, text = "Rate of reaction (k)", variable =
ksimparam).grid(row = 11, column = 1, sticky = W)
Checkbutton(paramroot, text = "Act Energy (A)", variable = Aparam).grid(row
= 12, column = 1, sticky = W)
Label(paramroot, text = "Order of reaction:").grid(row = 13, column=1,
sticky = W)
Checkbutton(paramroot, text = "Reactant A", variable = RAparam).grid(row =
13, column = 2, sticky = W)
Checkbutton(paramroot, text = "Reactant C", variable = RCparam).grid(row =
14, column = 2, sticky = W)

def SubmitParam():
global total_number_parameters
total_number_parameters = RCparam.get() + RAparam.get() + Aparam.get() +
ksimparam.get() + Afparam.get() + kfparam.get() + delHrxnparam.get() +
keqparam.get()
print total_number_parameters

for i in range(len(checkboxVars)):
if checkboxVars[i].get() == 1:
print checkboxVars[i]
selectedparam.append(checkboxVars[i])

print selectedparam


Button(paramroot, text = "Submit", command = SubmitParam).grid(row = 17,
column = 3, sticky =W)


butt1 = Button(explorer, text = "Parameters to be estimated",width = 15,
command = EstimateParameters)
butt1.pack(side = TOP)
butt1.config(font=("",9))

The highlighted area is where I am checking if the checkbutton is selected
and if selected, I am trying to append the variable name in the list
checkboxVar to the new list-selectedparam.

however, when I try to print selectedparam, I get the following output:
[<Tkinter.IntVar instance at 0x104829098>, <Tkinter.IntVar instance at
0x104829128>]
And when I try to print out checkboxVar[i] which is just above the previous
line, I get PY_VAR2
PY_VAR3

Can someone please let me know where I am going wrong?

Thankyou

Pooja


More information about the Tutor mailing list