【问题标题】:Kivy: How to add padding to a Text InputKivy:如何为文本输入添加填充
【发布时间】:2017-06-07 04:24:20
【问题描述】:

这里只是一个简单的问题 - 我想在我的文本输入框中添加一些“填充”,以便将其与上面的标签对齐:参见 here

以下是我的 .kv 文件的相关部分:

<InstructionsLabel>:
    font_size: 24
    size_hint_y: None
    color: 0.447, 0.094, 0.737, 1
    text_size: root.width, None
    size: self.texture_size
    padding_x: 20

<LengthExactScreen>:
    canvas.before:
        Color:
            rgba: 1, 1, 1, 1
        Rectangle:
            pos: self.pos
            size: self.size
    FloatLayout:
        DirectionButton:
            text: "Back"
            pos_hint: {'left': 1, 'top': 1}
            on_press:
                root.manager.transition.duration = 0
                root.manager.current = "tool_screen"
        DirectionButton:
            text: "Done"
            pos_hint: {'right': 1, 'top': 1}
            on_press: root.compute_orders(root.itemList, int(len_exact_input.text))
    GridLayout:
        cols: 1
        pos_hint: {'top': 0.86}
        BoxLayout:
            size_hint_y: None
            height: self.minimum_height
            orientation: "vertical"
            InstructionsLabel:
                text: "Enter the number of items you want to order"
            TextInput:
                id: len_exact_input
                size_hint: None, None
                width: 300
                height: 35
                multiline: False
                hint_text: ""

【问题讨论】:

  • 您需要为 size_hint 提供一个值:

标签: python python-3.x kivy kivy-language


【解决方案1】:

TextInput 还有一个 padding 属性。

更改此项以匹配标签上的填充

TextInput:
    padding_x:[20,0]

这是我编写的一个示例应用程序,用于查看从您的代码中采用的应用程序。不幸的是,您的代码有几个问题,这样做更容易

from kivy.app import App
from kivy.base import Builder
from kivy.uix.boxlayout import BoxLayout

Builder.load_string("""
<rootwi>:
    orientation: 'vertical'
    Label:
        font_size: 24
        text: 'iuqwdouqwdoqdwpqwpow'
        color: 0.447, 0.094, 0.737, 1
        text_size: root.width, None
        size: self.texture_size
        padding_x: 20
    TextInput:
        padding_x:[20,0]
""")
class rootwi(BoxLayout):
    pass

class MyApp(App):
    def build(self):
        return rootwi()


if __name__ == '__main__':
    MyApp().run()

【讨论】:

【解决方案2】:

你也可以做一些研究@kivy text input。这应该会为您提供所需的所有信息以及更多信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-29
    • 2015-02-24
    • 1970-01-01
    • 1970-01-01
    • 2017-12-12
    • 2021-08-04
    • 1970-01-01
    • 2013-06-18
    相关资源
    最近更新 更多