Signals for GtkEntry widgets

Alistair Thomas astavale at yahoo.co.uk
Fri Sep 13 20:48:34 CEST 2002


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 ()


--
	Al



More information about the Python-list mailing list