Signals for GtkEntry widgets
D. Shifflett
shifflett at nps.navy.mil
Tue Sep 17 14:24:16 EDT 2002
I have found that the 'activate' event/signal occurs
when the Enter key is pressed in a GtkEntry widget.
Here is a snippet:
# field for text from user
usertext = GtkEntry()
usertext.connect("activate", userinput)
Thanks for your help
David Shifflett
"Alistair Thomas" <astavale at yahoo.co.uk> wrote in message news:<6qqg9.509135$Aw4.21217664 at bin2.nnrp.aus1.giganews.com>...
> In article <mailman.1031866395.5190.python-list at python.org>, "David
> Shifflett" <shifflett at nps.navy.mil> wrote:
>
> > I am trying to find which signal is emitted when the user presses Enter
> > while in a GtkEntry widget.
>
> The signal is key_press_event. Which returns a GdkEvent object. The
> keyval attribute tells you which key was pressed.
>
> I use Glade and my sample code is based on my own module which uses libglade,
> hope this helps:
>
> import gtk, GDK
>
> # My own module based on libglade:
> import window
>
> class text_entry ( window.open ):
>
> def __init__ ( self, title = 'Enter text:', text = '' ):
> window.open.__init__ ( self, 'text_entry' )
> self.add_handlers ( { 'on_key_press' : self.key_press,
> 'closed' : self.closed } )
> self.get_widget ( 'text_entry' ).set_title ( title )
> self.modified = 0
> self.text = text
> a = self.get_widget ( 'text' )
> a.set_text ( text )
> a.grab_focus ()
> gtk.mainloop ()
>
> def key_press ( self, widget = None, event = None ):
> if event.keyval in [GDK.Return, GDK.KP_Enter] :
> self.text = widget.get_text ()
> self.modified = 1
> self.close ()
> gtk.mainquit ()
>
> def closed ( self, widget = None ):
> gtk.mainquit ()
More information about the Python-list
mailing list