Advertisement
metalx1000

GTK Key Press Secret Code - idqd

Aug 21st, 2013
455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.51 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.vbox=gtk.VBox()
  13.         self.win.add(self.vbox)
  14.         self.win.connect("key-press-event", self.closeme)
  15.         self.win.connect("key-press-event", self.code)
  16.         for i in range(0,5):
  17.             filename="/usr/share/dict/words"
  18.             file=open(filename,'r')
  19.             file_size=os.stat(filename)[6]
  20.             file.seek((file.tell()+random.randint(0,file_size-1))%file_size)
  21.             file.readline()
  22.             line=file.readline()
  23.  
  24.             self.button=gtk.Button(line)
  25.             self.button.connect("clicked", self.Title_Changer, line)
  26.  
  27.             self.vbox.pack_start(self.button)
  28.         self.win.show_all()
  29.  
  30.     def Title_Changer(self, widget, title):
  31.         self.win.set_title(title)        
  32.  
  33.     def closeme(self, widget, event):
  34.         if event.keyval == gtk.keysyms.Escape:
  35.             gtk.main_quit()
  36.  
  37.     def code(self, widget, event):
  38.         if event.keyval == gtk.keysyms.i:
  39.             self.CODE="i"
  40.         else:
  41.             self.CODE=self.CODE + chr(event.keyval)
  42.         print self.CODE
  43.         if self.CODE == "idqd":
  44.             self.CODE=''
  45.             self.alert()
  46.  
  47.     def alert(self):
  48.         msgbox = gtk.MessageDialog(self.win,gtk.DIALOG_DESTROY_WITH_PARENT,gtk.MESSAGE_WARNING,gtk.BUTTONS_CLOSE, "You Win" )
  49.         msgbox.run()
  50.         msgbox.destroy()
  51.  
  52. mainapp=[]
  53.  
  54. for i in range(1,4):
  55.     mainapp.append(WIN())
  56. gtk.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement