[Tutor] Tkinter class question - solved

Alan Gauld alan.gauld at yahoo.co.uk
Sat Apr 8 07:16:11 EDT 2017


On 07/04/17 20:21, Phil wrote:

> After a bit more thought I now realise that I just 
> need to use self to reference e[][] in my check function.

You need to use self any time you access any member of your
class. So in your case:

class TestGUI:
    def __init__(self, master):
        self.master = master
...
        self.e = [[None] * num_cols for _ in range(num_rows)]
...
        self.check_button = Button(master,text="Check",
                                   command=self.check)
...

    def check(self,array): ...

The following attributes all need to be prefixed with self
any time you access them:

self.master
self.e
self.check_button
self.check

In this specific case you only need to use self.e

HTH

-- 
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




More information about the Tutor mailing list