Advertisement
metalx1000

Python GTK get keypressed

Aug 29th, 2017
812
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import gtk,os,random
  4.  
  5. class WIN:
  6.     def __init__(self):
  7.         self.CODE=""
  8.         self.win=gtk.Window()
  9.         self.win.connect("destroy", lambda w:gtk.main_quit())
  10.         self.win.show()
  11.  
  12.         self.win.connect("key-press-event", self.closeme)
  13.         self.win.connect("key-press-event", self.code)
  14.  
  15.     def closeme(self, widget, event):
  16.         if event.keyval == gtk.keysyms.Escape:
  17.             gtk.main_quit()
  18.  
  19.     def code(self, widget, event):
  20.         if event.keyval == gtk.keysyms.i:
  21.             self.CODE="i"
  22.         else:
  23.             self.CODE+= chr(event.keyval)
  24.             print self.CODE
  25.         if self.CODE == "idqd":
  26.             self.CODE=''
  27.  
  28. mainapp=WIN()
  29. gtk.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement