【问题标题】:Multiple text fields inside of kivy text inputkivy文本输入中的多个文本字段
【发布时间】:2020-06-07 12:49:25
【问题描述】:

我正在使用 kivy 开发科学计算器,有没有一种方法可以在 kivy 文本输入中插入多个文本字段,如下图所示。谢谢你的帮助。

【问题讨论】:

    标签: python kivy kivy-language


    【解决方案1】:

    不确定您到底想要什么,但您可以组合 TextInput 小部件。这是一个例子:

    from kivy.app import App
    from kivy.factory import Factory
    from kivy.lang import Builder
    
    kv = '''
    <-TextInputNoBorder@TextInput>:
        # eliminates the TextInput border
        canvas.before:
            Color:
                rgba: self.background_color
            Rectangle:
                pos: self.pos
                size: self.size
            Color:
                rgba:
                    (self.cursor_color
                    if self.focus and not self._cursor_blink
                    else (0, 0, 0, 0))
            Rectangle:
                pos: self._cursor_visual_pos
                size: root.cursor_width, -self._cursor_visual_height
            Color:
                rgba: self.disabled_foreground_color if self.disabled else (self.hint_text_color if not self.text else self.foreground_color)
    
    <MyTextInput@BoxLayout>:
        # combine three TextInput Widgets to appear as one
        orientation: 'vertical'
        TextInputNoBorder:
            id: ti1
            text: 'This is One'
        TextInputNoBorder:
            id: ti2
            text: 'This is Two'
        TextInputNoBorder:
            id: ti3
            text: 'This is Three'
    '''
    
    class TestApp(App):
        def build(self):
            Builder.load_string(kv)
            return Factory.MyTextInput()
    
    TestApp().run()
    

    这个例子只是垂直堆叠了三个TextInput 小部件,但它们可以通过多种方式排列和调整大小。 TextInputNoBorder 小部件通过重新定义其外观(消除边框)扩展了 TextInput 小部件。

    【讨论】:

    • 谢谢。但是我运行这段代码并得到 attributeError: 'TextInputNoBorder' object has no attribute '_cursor_visual_pos'
    • 这是在TextInput 中定义的,我的代码不会影响该定义。您的代码中肯定发生了其他事情。
    • 我让代码运行,但这并不能解决我的问题。我想要一个正确的数学格式。
    • 这与TextInput 中的字段无关。这就是字体。
    • 字体?但是我使用的是 asana 字体,或者有没有更好的字体可以达到这个目的?
    猜你喜欢
    • 2019-12-11
    • 1970-01-01
    • 1970-01-01
    • 2011-04-11
    • 1970-01-01
    • 1970-01-01
    • 2020-03-14
    • 2016-06-07
    • 2017-10-06
    相关资源
    最近更新 更多