Global NameError Fix?

David Robinow drobinow at gmail.com
Thu Mar 21 21:04:14 EDT 2013


On Thu, Mar 21, 2013 at 7:43 PM, maiden129 <sengokubasarafever at gmail.com> wrote:
> Hello,
>
> I'm using the version 3.2.3 of Python and I am having an issue in my program and I don't know how to fix it:
>
> counterLabel["text"] = str(counter)
> NameError: global name 'counterLabel' is not defined
>
> Here is my program:
>
> from tkinter import *
> class CounterButton(Button):
>     def __init__(self, window):
>        super(CounterButton,self).__init__(window, text = "0", command=self.startCounter)
>
>     def startCounter(self):
>         counter = int(self["text"])
>         counter +=1
>         counterLabel["text"] = str(counter)
This should be:
           self["text"] = str(counter)
>
> window = Tk()
> window.title("counter")
...



More information about the Python-list mailing list