On Mon, Sep 21, 2009 at 4:00 PM, kreglet <kreg...@gmail.com> wrote:

>
> I keep getting the following error and don't uderstand why:
>
> Traceback (most recent call last):
>  File "/home/kreglet/bin/test.py", line 15, in btnStatclick
>    btnStat.set_label("Pressed")
> NameError: global name 'btnStat' is not defined
>
>
> #!/usr/bin/env python
>
> import gtk
> import sys
>
> class NewAppWindow(gtk.Window):
>
>    def btnStatclick(self, widget, data=None):
>        #print status
>        if self.status == True:
>            btnStat.set_label("Not Pressed")
>            self.status =False
>            print self.status
>        elif self.status == False:
>            btnStat.set_label("Pressed")
>            self.status =True
>            print self.status


btnStat isn't defined here. I think you should be declaring a self.btnStat
in the __init__ method (which I usually put as the first function in my
class - I'm honestly not sure if it makes a difference), and calling
self.btnStat

Unlike C/C++, python is explicit when dealing with members of the class. I'm
not sure if anything is implied when it comes to namespaces, but I'm pretty
sure it's all gotta be specific.

HTH,
Wayne
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to