[Tutor] Checking if a GtkEntry is empty

Prasad, Ramit ramit.prasad at jpmorgan.com
Sat Feb 25 00:55:29 CET 2012

>def on_btnSearch_click(self, data=None):
>    if btnSearch.get_text() == "":
>        print "Nothing to search"
>    else:
>        print "I would do this search"

>The code above does nothing. No error, no print, nothing. Any idea?

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

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

Typically print statements are not seen in UI applications because they
are not run from command very often or the loop in charge of handling
events swallows them (which is what happens in an IDE). I would recommend
using a popup window or changing the text of a field instead. Or you can
use the python logger and just look at the log file afterwards.


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  

More information about the Tutor mailing list