[pygtk] keyboard emulation with button

Fabrizio Pollastri pollastri at iriti.cnr.it
Tue Feb 28 23:38:32 WST 2006


I am trying to emulate a keyboard with gtk buttons to entry some text 
into a gtk.Entry. All works fine, but I get the following errors.

(myprogram.py:2165): Gdk-CRITICAL **: gdk_drawable_get_display:
assertion `GDK_IS_DRAWABLE (drawable)' failed

(myprogram.py:2165): Gdk-CRITICAL **: gdk_keymap_get_for_display:
assertion `GDK_IS_DISPLAY (display)' failed


Here is my code.
--------------------
#!/usr/bin/python2.3

import gtk

# build a window with an entry and a button
window = gtk.Window()
hbox = gtk.HBox()
entry = gtk.Entry(max=20)
button = gtk.Button(label="button")
window.add(hbox)
hbox.add(entry)
hbox.add(button)

# the event of pressing a key with key value "A"
event =   gtk.gdk.Event(gtk.gdk.KEY_PRESS)
event.keyval = ord("A")

# button pressing handler: simulate pressing of keyboard key "A"
def on_button_pressed(button,entry):
   entry.emit("key_press_event",event)

# connect button press even with handler
button.connect("pressed",on_button_pressed,entry)

# start GTK
window.show_all()
gtk.main()
----------

Thanks in advance for any help.

Fabrizio Pollastri.


More information about the pygtk mailing list