demo_input.py
changeset 41 37b7dfc3eae6
parent 20 472a753664f9
child 45 43b2279b06e1
equal deleted inserted replaced
40:5faa38c10b67 41:37b7dfc3eae6
     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.globalkeypress)
    13         self.top.connect('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 
    21 
    22     def globalkeypress(self, keyname, char):
    22     def on_top_keypress(self, ev):
    23         if char == 'q':
    23         if ev.char == 'q':
    24             self.terminate()
    24             self.terminate()
    25         self.text += 'keyname: %s  char: %s\n' % (keyname, char)
    25         self.text += 'keyname: %(keyname)s  char: %(char)s\n' % ev
    26         self.textedit.settext(self.text)
    26         self.textedit.settext(self.text)
    27         self.textedit.scrolltoend()
    27         self.textedit.scrolltoend()
    28 
    28 
    29 
    29 
    30 if __name__ == '__main__':
    30 if __name__ == '__main__':