Kivi,在布局文件中调整按钮大小

时间:2021-05-07 10:30:47

标签: python kivy widget

在我的代码中,我在用户登录时调整大小并尝试隐藏按钮。问题是登录按钮由于未知原因没有正确响应。

        Label:
            halign: 'center'
            valign: 'middle'
            text_size: self.size
            size_hint_x: .5
            text: root.text
        PrimaryButton:
            text: "Manage" if (root.text != '') else ""
            size_hint_x: .25 if (root.text != '') else 0
            opacity: 1 if (root.text != '') else 0
            disabled: False if (root.text != '') else True
            on_release:
                root.logout() if (root.text != '') else root.changeScreen("AccountCreation")
                root.manager.transition.direction = "down"
        PrimaryButton:
            text: "Log Out" if (root.text != '') else "Log In"
            size_hint_x: .25 if (root.text != '') else .5
            on_release:
                root.logout() if (root.text != '') else root.changeScreen("AccountCreation")
                root.manager.transition.direction = "down"

Not logged in

Logged in

1 个答案:

答案 0 :(得分:0)

想通了,第一个按钮应该有这个参数-

size_hint: (.25, 1) if (root.text != '') else (None, 1)

宽度:0 if (root.text != '') else 0

相关问题