开发者

Pygtk: Name is not defined

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开发者_Python百科 = 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


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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜