如何在Kivy中触摸TextInput Field时弹出一个用于输入文本的键盘?

时间:2020-10-15 07:20:31

标签: python kivy textinput

目前,我能够在Kivy中渲染TextInput字段。但是,当我触摸该字段时,不会弹出键盘。

这是我的脚本中的内容:

Config.set('graphics', 'fullscreen', 'auto')
Config.set('graphics', 'resizable', True)
Config.set('kivy', 'keyboard_mode', 'systemandmulti')

class PhoneInput(TextInput):
    max_characters = NumericProperty(12)
    pos = ListProperty([200,250])
    font_size = NumericProperty(30)
    size_hint=ListProperty([.5,.15])
    color = ListProperty([0,0,0,1])
    input_type = StringProperty('number')

    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)

    def _keyboard_close(self):
        pass

    def setup_keyboard(self):
        kb = Window.request_keyboard(self._keyboard_close, self)
        if kb.widget:
            kb.widget.layout = 'numeric.json'


class AddPhoneScreen(App):

    def build(self):
        Fl = FloatLayout()
        Fl.add_widget(PhoneInput())
        return Fl

AddPhoneScreen().run()

当前点击该字段时,没有显示键盘。在点击时,TextInput字段显示键盘需要什么?

0 个答案:

没有答案