demo_input.py
changeset 20 472a753664f9
parent 19 5e78d52ebb24
child 41 37b7dfc3eae6
equal deleted inserted replaced
19:5e78d52ebb24 20:472a753664f9
       
     1 #!/usr/bin/env python3
       
     2 # -*- coding: utf-8 -*-
       
     3 
       
     4 import locale
       
     5 locale.setlocale(locale.LC_ALL, '')
       
     6 
       
     7 from tuikit import *
       
     8 
       
     9 
       
    10 class MyApplication(Application):
       
    11     def __init__(self):
       
    12         Application.__init__(self)
       
    13         self.top.connect('keypress', self.globalkeypress)
       
    14 
       
    15         self.text = ''
       
    16         textedit = TextEdit(100, 40, self.text)
       
    17         self.top.add(textedit)
       
    18         textedit.x = 2
       
    19         self.textedit = textedit
       
    20 
       
    21 
       
    22     def globalkeypress(self, keyname, char):
       
    23         if char == 'q':
       
    24             self.terminate()
       
    25         self.text += 'keyname: %s  char: %s\n' % (keyname, char)
       
    26         self.textedit.settext(self.text)
       
    27         self.textedit.scrolltoend()
       
    28 
       
    29 
       
    30 if __name__ == '__main__':
       
    31     app = MyApplication()
       
    32     app.start()
       
    33