Set the width property for textinput

妖精的绣舞 提交于 2019-12-02 04:10:43

By width I'm assuming you mean text length, as setting the width of a widget is just as easy as setting the height is.

There is an example of text filtering in the documentation you linked which could easily be modified to limit the length:

class MyTextInput(TextInput):
    def insert_text(self, substring, from_undo=False):
        # limit to 5 chars
        substring = substring[:5 - len(self.text)]
        return super(MyTextInput, self).insert_text(substring, from_undo=from_undo)


If you happen to be running the development version of Kivy (1.8.1-dev, from git), this is even easier and can be done from kv. You can limit the length of the text with a callable input_filter. Here's a quick example:

TextInput:
    # limit to 5 chars
    input_filter: lambda text, from_undo: text[:5 - len(self.text)]
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!