[pygtk] increase number in gtk.entry by pressing '+'

Eike Nicklas lists at ephys.de
Thu Jan 10 08:23:15 WST 2008


Hi all,

I am currently learning PyGTK and got stuck on the following problem:

I have myentry = gtk.Entry() containing an integer (actually a string,
of course, but int(myentry.get_text()) works) and want to increase this
integer by one if the button '+' is pressed.

Here's what I tried:

myentry.connect('key-press-event', increase)

def increase(entry, event):
	if event.keyval == gtk.keysyms.plus:
		mynumber = int(entry.get_text())
		mynumber += 1
		entry.set_text(str(mynumber))

This works at first, but the '+' is inserted into the text entry after
the number was increased. Do you have an idea how to prevent this?

A related problem is covered in the FAQ at

http://faq.pygtk.org/index.py?req=show&file=faq14.005.htp

but I was not able to modify this (outdated ?) code to my needs :-(

Thanks a lot for your help,

Eike


More information about the pygtk mailing list