Re: [Tutor] trouble using tkinter CheckButton

2018-01-16 Thread Chris Roy-Smith

On 16/01/18 22:35, Alan Gauld via Tutor wrote:

On 16/01/18 04:37, Chris Roy-Smith wrote:


    File "./debugString.py", line 7, in SetFin
      SetStatus[x] = var.get(x)
AttributeError: 'list' object has no attribute 'get'
var=[IntVar() for x in range(8)]

Here you create a list of IntVar objects.
The list has no get() method - just as the error message says.
You need to access the individual IntVar for your widget.

I suspect you want

   SetStatus[x] = var[x].get()

Yes, Thank you, that was the problem. other problems in my code, after 
correcting the get() were easy to sort out.


Regards, Chris Roy-Smith

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] trouble using tkinter CheckButton

2018-01-16 Thread Alan Gauld via Tutor
On 16/01/18 04:37, Chris Roy-Smith wrote:

>    File "./debugString.py", line 7, in SetFin
>      SetStatus[x] = var.get(x)
> AttributeError: 'list' object has no attribute 'get'

> var=[IntVar() for x in range(8)]

Here you create a list of IntVar objects.
The list has no get() method - just as the error message says.
You need to access the individual IntVar for your widget.

I suspect you want

  SetStatus[x] = var[x].get()

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] trouble using tkinter CheckButton

2018-01-16 Thread Chris Roy-Smith

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@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 
    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()

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor