[Tutor] Help with class in class

Kwpolska kwpolska at gmail.com
Sun Sep 9 18:57:35 CEST 2012


On Sun, Sep 9, 2012 at 5:43 PM, leam hall <leamhall at gmail.com> wrote:
> Of course, showing the code might help...
>
>  http://bpaste.net/show/44593/
>
> Thanks!
>
> Leam
>
>
> On Sun, Sep 9, 2012 at 10:42 AM, leam hall <leamhall at gmail.com> wrote:
>>
>> I'm in the O'Reilly Python 2 class, so pointers to learning would be
>> better than just answers, please. My brain is a bit slow but needs to go
>> forward.
>>
>> Line 16 calls line 31. Rather, it is supposed to. I'm trying to figure out
>> why I get
>>
>>   File "./ch8_project.py", line 31, in change_text_color
>>     self.text.tag_configure('highlightline', foreground=fg_color)
>> AttributeError: 'ch8_Project' object has no attribute 'text'
>>
>> If line 31 starts with "self." and
>>
>>   File "./ch8_project.py", line 31, in change_text_color
>>     text.tag_configure('highlightline', foreground=fg_color)
>> NameError: global name 'text' is not defined
>>
>>
>> If Line 31 does not start with "self.". I understand the second problem
>> but not the first.
>>
>> What am I missing?
>>
>> Thanks!
>>
>> Leam
>>
>>
>> --
>> Mind on a Mission
>>
>
>
>
> --
> Mind on a Mission
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

Please do not top post.
---
And the problem is: add_text_widget() defines a local (function-wide)
`text` object rather than a class-wide one.  Just prepend the `text`
object with `self.` and it will be solved.  Also, if you are planning
to use more than one of those, you will need to do it in another way.
Bonus question: why py3k?

-- 
Kwpolska <http://kwpolska.tk>
stop html mail      | always bottom-post
www.asciiribbon.org | www.netmeister.org/news/learn2quote.html
GPG KEY: 5EAAEA16


More information about the Tutor mailing list