demo_input.py
changeset 45 43b2279b06e1
parent 41 37b7dfc3eae6
child 55 1ab0edd5d784
equal deleted inserted replaced
44:d77f1ae3786c 45:43b2279b06e1
     8 
     8 
     9 
     9 
    10 class MyApplication(Application):
    10 class MyApplication(Application):
    11     def __init__(self):
    11     def __init__(self):
    12         Application.__init__(self)
    12         Application.__init__(self)
    13         self.top.connect('keypress', self.on_top_keypress)
    13         self.top.add_handler('keypress', self.on_top_keypress)
    14 
    14 
    15         self.text = ''
    15         self.text = ''
    16         textedit = TextEdit(100, 40, self.text)
    16         textedit = TextEdit(100, 40, self.text)
    17         self.top.add(textedit)
    17         self.top.add(textedit)
    18         textedit.x = 2
    18         textedit.x = 2
    19         self.textedit = textedit
    19         self.textedit = textedit
    20 
    20 
    21 
       
    22     def on_top_keypress(self, ev):
    21     def on_top_keypress(self, ev):
    23         if ev.char == 'q':
    22         if ev.char == 'q':
    24             self.terminate()
    23             self.terminate()
    25         self.text += 'keyname: %(keyname)s  char: %(char)s\n' % ev
    24         self.text += 'keyname: %(keyname)s  char: %(char)s\n' % ev
    26         self.textedit.settext(self.text)
    25         self.textedit.settext(self.text)
    27         self.textedit.scrolltoend()
    26         self.textedit.scrolltoend()
       
    27         return True
    28 
    28 
    29 
    29 
    30 if __name__ == '__main__':
    30 if __name__ == '__main__':
    31     app = MyApplication()
    31     app = MyApplication()
    32     app.start()
    32     app.start()