小编bla*_*kel的帖子

Kivy:如何检查子部件是否存在

在我的 .py 文件中,我有一个看起来像这样的屏幕:

class ExampleScreen(Screen):
    def create_layout(self):
        box = BoxLayout(orientation='vertical')
        # other layout stuff in here
        self.add_widget(box)
Run Code Online (Sandbox Code Playgroud)

在我的 .kv 文件中,我有一个按钮,按下该按钮会调用此函数并在 .kv 文件上显示此布局<ExampleScreen>。但是,我希望能够按下此按钮并首先检查此布局是否已存在,如果存在,请在添加新布局之前将其删除。我预计会修改create_layout()为:

def create_layout(self):
    if (box layout child has already been added):
        self.remove_widget(box layout child)
    box = BoxLayout(orientation='vertical')
    # other layout stuff in here
    self.add_widget(box)
Run Code Online (Sandbox Code Playgroud)

有谁知道如何做到这一点?以某种方式使用id?

python python-3.x kivy kivy-language

5
推荐指数
1
解决办法
4772
查看次数

Kivy:如何向文本输入添加填充

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

以下是我的 .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 …
Run Code Online (Sandbox Code Playgroud)

python python-3.x kivy kivy-language

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

kivy ×2

kivy-language ×2

python ×2

python-3.x ×2