kivy文本输入中的多个文本字段

问题描述 投票:0回答:1

我正在研究使用基维的科学计算器,有没有一种方法可以在基维文本输入中插入多个文本字段,如下图所示。谢谢你的帮助。enter image description here

python kivy kivy-language
1个回答
0
投票

不确定您想要的是什么,但是您可以结合使用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小部件的外观(消除边框)来扩展。

© www.soinside.com 2019 - 2024. All rights reserved.