[Tutor] trouble using tkinter CheckButton
Chris Roy-Smith
chris_roysmith at internode.on.net
Mon Jan 15 23:37:17 EST 2018
Hi,
I'm a relative newcomer to object oriented programming.
Operating system Linux (ubuntu 17.10)
Python version 3.6
With the code below, when I click on the "list set & unset" button I get
the following error. This code is my attempt at debugging a bigger
program. I have broken things down to what I think is as simple as I can
get.
Thank you for looking at this,
Regards, Chris Roy-Smith
Error message:
=====================
chris at chris-X451MA:~/Scripts/python3/dvms$ ./debugString.py
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.6/tkinter/__init__.py", line 1702, in __call__
return self.func(*args)
File "./debugString.py", line 26, in <lambda>
Button(cmember, text='list set & unset',command= lambda lines = x :
SetFin(lines) ).grid(row=x, column=2)
File "./debugString.py", line 7, in SetFin
SetStatus[x] = var.get(x)
AttributeError: 'list' object has no attribute 'get'
============================================
#!/usr/bin/python3
from tkinter import *
def SetFin(lines):
SetStatus=[" " for i in range(lines)]
for x in range(lines):
SetStatus[x] = var.get(x)
print (SetStatus(x))
master = Tk()
NameList=[(1, 'Vivian', 'Blackwell'), (2, 'Peter ', 'Bromell'), (3,
'Nev', 'Casey'), (4, 'Claude', 'Chatwin'), (5, 'John ', 'Dennison'), (6,
'Nicolene', 'Fairbrass'), (7, 'Paul', 'Fairbrass')] #in real situation
this comes from a database and is of variable length
cmember=Toplevel(master)
x=0
y=0
var=[IntVar() for x in range(8)]
for line in NameList:
for field in line:
Label(cmember, text=field).grid(row=x, column=y)
y+=1
#make checkbox
cb=Checkbutton(cmember, text='set', variable=var[x]).grid(row=x,
column=y)
y=0
x+=1
Button(cmember, text='list set & unset',command= lambda lines = x :
SetFin(lines) ).grid(row=x, column=2)
Button(cmember, text='exit', command=cmember.destroy).grid(row=x, column=4)
mainloop()
More information about the Tutor
mailing list