AttributeError: 'NoneType' object has no attribute 'get_text'

Raji Seetharaman sraji.me at gmail.com
Mon Sep 14 16:30:25 CEST 2009


> ---------- Forwarded message ----------
> From: MRAB <python at mrabarnett.plus.com>
> To: python-list at python.org
> Date: Sun, 13 Sep 2009 19:44:30 +0100
> Subject: Re: AttributeError: 'NoneType' object has no attribute 'get_text'
> Raji Seetharaman wrote:
>
>> Hi all,
>> i did a small gui addressbook application using pygtk, python, mysql db.
>> It was successful.
>> I tried the same application with glade. But i ended up with errors.
>> I desgined the code as follows.
>> 1.It has one main window and four child dialogs.
>> 2.In the main window, i have to fill in the text entry widget & if i press
>> 'add', the data will get inserted into the database.This works fine.
>> 3. If showdialog button is clicked, a child dialog appears, where i have
>> to enter old entry to update.
>> 4. To update, i again use the main window, where i get the following error
>>                  Traceback (most recent call last):
>>  File "addressbookglade.py", line 63, in update
>>    self.ssn = self.wTree.get_widget("ssn").
>> get_text()
>>    AttributeError: 'NoneType' object has no attribute 'get_text'
>>
>> Also i already set the name in properties window.  It works fine for add
>> option. But not for update option.
>> Im using the same window for both add and update.
>>
>> The code is available here http://pastebin.com/m28a4747e
>> The glade xml file is here http://pastebin.com/m1af61a29
>> The screenshot of my glade windows are here
>> http://www.flickr.com/photos/raji_me/?saved=1
>>  It works fine for add option. But not for update option. Im using the
>> same window for both add and update.
>>
>>  You're using instance attributes a lot where I think local variables
> would be better, eg "self.ssn" instead of just "ssn".
>
> In the '__init__' method you have:
>
>    self.wTree = gtk.glade.XML(self.gladefile,"mainWindow")
>
> and then in the 'view' method you have:
>
>    self.wTree = gtk.glade.XML(self.gladefile,"viewdialog")
>
> In both the 'add' and 'update' methods you have:
>
>    self.ssn = self.wTree.get_widget("ssn").get_text()
>
> so I suspect that the following is happening:
>
> 1. __init__ makes self.wTree refer to 'mainWindow';
>
> 2. You click on the Add button, the 'add' method is called, and the
> "self.ssn = " line looks for the "ssn" widget in 'mainWindow';
>
> 3. You click on the OK(?) button and view what's just been added;
>
> 4. The 'view' method makes self.wTree refer to 'viewdialog';
>
> 5. You click on the Update button, the 'update' method is called, and the
> "self.ssn = " line looks for the "ssn" widget in 'viewdialog'.
>



>
> Yes, u r right, the "self.ssn = " looks for widget in the child dialog, not
> the mainWindow. But how to set it to 'mainWindow' again.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090914/ac91356d/attachment.html>


More information about the Python-list mailing list