[Tutor] Checking if a GtkEntry is empty

Anthony Papillion papillion at gmail.com
Sat Feb 25 01:22:27 CET 2012


On Fri, Feb 24, 2012 at 5:55 PM, Prasad, Ramit
<ramit.prasad at jpmorgan.com> wrote:
>
> How are you running this? I assume from an IDE because this should most
> likely cause an error. I would recommend trying to run your python script
> from the commandline which is much more likely to print an error.
>
> $python your_script.py

Hi Ramit,

I'm running this from terminal in exactly the way you're saying.

> btnSearch.get_text() should be self. btnSearch.get_text()

When I change the code as you suggest, I'm getting this error:

if self.btnSearch.text == "":
AttributeError: 'DocuManager' object has no attribute 'btnSearch'

Here is the entire text of the code I have so far:

#!/usr/bin/env python

import pygtk
pygtk.require("2.0")
import gtk
import sqlite3 as lite

class Manager(object):
    def __init__(self):
        builder = gtk.Builder()
        builder.add_from_file("winMain.glade")
        builder.connect_signals(self)
        self.window = builder.get_object("winMain")
        self.window.show()

        conn = None
        try:
            conn = lite.connect('docs.db')
            sql =  "create table if not exists documents(id integer,
name text, location text, tags text)"
            c = conn.cursor()
            c.execute(sql)
            conn.commit()
        except lite.Error, e:
            print "Error: " + e.args[0]


    def on_btnSearch_clicked(self, data=None):
        if self.btnSearch.text == "":
            print "No text"
        else:
            print "There is text"

    def on_tbExit_clicked(self, data=None):
       exit()


if __name__ == "__main__":
    app = Manager()
    gtk.main()


More information about the Tutor mailing list