Guest User

Untitled

a guest
Feb 25th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. from kivy.app import App
  2. from kivy.uix.textinput import TextInput
  3. from kivy.properties import NumericProperty
  4.  
  5.  
  6. class MyTextInput(TextInput):
  7. max_characters = NumericProperty(0)
  8. def insert_text(self, substring, from_undo=False):
  9. if len(self.text) > self.max_characters and self.max_characters > 0:
  10. return
  11. TextInput.insert_text(self, substring, from_undo)
  12.  
  13. class MyApp(App):
  14. def build(self):
  15. return MyTextInput(max_characters=4)
  16.  
  17.  
  18. if __name__ == '__main__':
  19. MyApp().run()
Add Comment
Please, Sign In to add comment