tags:

views:

32

answers:

3

I'm trying out a few pygtk tutorials and have run across a seemingly obvious newbie mistake, but for the life of me can't figure out what's going on here.

The error:

Traceback (most recent call last):
  File "main.py", line 8, in 
    class Base:
  File "main.py", line 61, in Base
    cv.set_line_width(9)
NameError: name 'cv' is not defined

The code:

def expose(self, widget, data=None):  
    cv = widget.window.cairo_create()      
    cv.set_line_width(9)
    cv.set_source_rgb(0.7, 0.2, 0.0)

    w = self.window.allocation.width
    h = self.window.allocation.height

    cv.translate(w/2, h/2)
    cv.arc(0, 0, 50, 0, 2*math.pi)
    cv.stroke_preserve()

    cv.set_source_rgb(0.3, 0.4, 0.6)
    cv.fill()

Here is the full source: http://gist.github.com/655728

+1  A: 

Your code in github reads:

def expose(self, widget, data=None):        
    selcv = widget.window.cairo_create()

    cv.set_line_width(9)
    cv.set_source_rgb(0.7, 0.2, 0.0)

...which would surely explain why cv is not defined when you try to access it.

Jim Brissom
Sorry that's a typo in the gist. Thanks for pointing it out
Orb
A: 

This was solved by switching to 4-space indents instead of tabs and re-indenting the entire file.

Something weird was going on, gedit was showing everything nicely indented while Netbeans showed the indent culprit

Orb
Welcome to SO. Am glad that things worked out for you. By the way, you're entitled to tick your own question, saying that you've accepted the answer. That lets people know that they don't need to worry about providing further thought.
Tim McNamara
A: 

You have a mixture of tabs and spaces in your file.

Ned Batchelder