I'm writing kivy app and resently I faced with a problem of unlimited inputing text in TextInput widget. Is there any solution to this problem?
A possible solution is to create a new property and overwrite the insert_text method:
from kivy.app import App
from kivy.uix.textinput import TextInput
from kivy.properties import NumericProperty
class MyTextInput(TextInput):
max_characters = NumericProperty(0)
def insert_text(self, substring, from_undo=False):
if len(self.text) > self.max_characters and self.max_characters > 0:
substring = ""
TextInput.insert_text(self, substring, from_undo)
class MyApp(App):
def build(self):
return MyTextInput(max_characters=4)
if __name__ == '__main__':
MyApp().run()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With