[Tutor] problem with msg widget & button

Wayne Werner waynejwerner at gmail.com
Tue Nov 29 17:06:08 CET 2011


On Tue, Nov 29, 2011 at 9:54 AM, Cranky Frankie <cranky.frankie at gmail.com>wrote:

> Peter Otten <__peter__ at web.de> wrote:
>
> <snip>

Isn't msg_widget an object, like everything else in Python. If so, why is
> it not
>
> def display_quote():
>   msg_widget.text = choose_quote()
>
> That is one of the things I tried. I don't understand why the ["test"]
> pair works above.
>

Just because msg_widget is an object doesn't automatically give it a .text
attribute. Just like the following dictionary (which is an object):

>>> knights = {'Aurthur': 'King of the Britons', 'Robin':'The Brave'}
>>> knights['Robin']
'The Brave'
>>> knights['Robin'] = 'The Coward'
>>> knights.Robin
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'dict' object has no attribute 'Robin'

They simply made a design choice to allow access to the data via index (in
this case "text" is the index), rather than by object attribute.

HTH,
Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111129/ec0c4611/attachment.html>


More information about the Tutor mailing list