Guest User

Untitled

a guest
Mar 21st, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. from kivy.app import App
  2. from kivy.lang import Builder
  3. from kivy.core.window import Window
  4. from kivy.uix.screenmanager import Screen, ScreenManager
  5. from kivy.uix.textinput import TextInput
  6.  
  7. kv = '''ScreenManagement:
  8. MainScreen:
  9.  
  10. <MainScreen>:
  11. name: "main"
  12. BoxLayout:
  13. Label:
  14. text: "Label"
  15. font_size: 20
  16. size_hint: 0.2,0.1
  17. TextInput
  18. input_filter: 'float'
  19. font_size: 20
  20. hint_text: "Input Text"
  21. size_hint: 0.2,0.1'''
  22.  
  23. class MainScreen(Screen):
  24.  
  25. def __init__(self, **kwargs):
  26. super().__init__(**kwargs)
  27. self._keyboard = Window.request_keyboard(self._keyboard_closed, self)
  28. self._keyboard.bind(on_key_down=self._on_keyboard_down)
  29.  
  30. def _keyboard_closed(self):
  31. self._keyboard.unbind(on_key_down=self._on_keyboard_down)
  32. self._keyboard = None
  33.  
  34. def _on_keyboard_down(self, keyboard, keycode, text, modifiers):
  35. print('INFO: The key', keycode, 'has been pressed')
  36.  
  37. return True # return True to accept the key. Otherwise, it will be used by the system.
  38.  
  39. class ScreenManagement(ScreenManager):
  40. pass
  41.  
  42. class MainApp(App):
  43. def build(self):
  44. return Builder.load_string(kv)
  45.  
  46. if __name__ == "__main__":
  47. MainApp().run()
Add Comment
Please, Sign In to add comment