Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Sorry for a newbie question but I could not figure out how to print a text which a user enter in a GTKEntry field after he press a button.

I design my app with glade, a simple TextEntry Field and a button. After I change the code of myappWindow.py:

  def on_button1_clicked(self, widget, data=None):
    print 'pressed'

  def entry1_changed_cb(self, widget, data=None):
    return widget.get_text ()

But now I couldn't find out how to print the text of the entry field after the user pressed the button.

Thanks for any help!

share|improve this question

1 Answer 1

up vote 5 down vote accepted

Use the get_object function of your builder to get the entry widget, for example

entry = self.builder.get_object('entry1')
print entry.get_text()

This assumes that self.builder is a Gtk.Builder instance that you assigned for example in your __init__ method using the get_builder function of the helpers module in yourproject_lib

share|improve this answer
    
Danke, sehr hilfreich! –  snowflake Jun 19 '12 at 20:01
    
If you are using Quickly and you've added your widget through Glade, you can also use self.ui.entry1.get_text(). Note that this is not standard GTK, simply a nice shortcut Quickly offers. –  David Planella Jun 20 '12 at 7:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.