【问题标题】:Button in kv file doesn't redirect to the desired pagekv 文件中的按钮未重定向到所需页面
【发布时间】:2022-01-17 20:37:56
【问题描述】:

您好,我的代码有问题:正如您在标题中看到的那样,我有这个按钮,它应该将用户重定向到另一个页面,但是当点击它时它没有任何作用。你能帮帮我吗?

这里是代码

我在这里定义按钮

<Home>:
    name: "home"

    BoxLayout:
        orientation: "vertical"
        pos_hint: {"center_x": .5}
        size_hint: .7, 1

        Label:
            text: "Home"
            font_size: 50

        Label:
            text: ""

        Button:
            text: "FAQ"
            on_release:
                app.root.current: "FAQ_AP"
                root.manager.transition.direction = "left"

        Label:
            text: ""

        Button:
            text: "Gestionale"
            on_release:

        Label:
            text: ""

在这里我创建了按钮应该重定向的页面:

<FAQ_AP>:
    name: "FAQ_AP"

    BoxLayout:
        orientation: "vertical"
        pos_hint: {"center_x": .5}
        size_hint: .7, 1

        Label:
            font_size: 50
            text: "Sei un'azienda o un privato?"

        Label:
            text: ""

        Label:
            text: ""

        Button:
            text: "Azenda"
            on_release:

        Label:
            text: ""

        Button:
            text: "Privato"
            on_release:

        Label:
            text: ""

如果你能帮助我,那将是最好的。提前谢谢你。

【问题讨论】:

  • 尝试将 app.root.current: "FAQ_AP" 更改为 app.root.current = "FAQ_AP"
  • 前段时间我已经想通了,但无论如何感谢您的帮助。

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


【解决方案1】:

您无需在按钮的on_release 功能中提及.app

用这个,效果很好

Button:
    text: "FAQ"
    on_release:
        root.manager.current = "FAQ_AP"
        root.manager.transition.direction = "left"

【讨论】:

    猜你喜欢
    • 2023-03-10
    • 1970-01-01
    • 2020-04-06
    • 2018-11-21
    • 1970-01-01
    • 2014-12-27
    • 2015-11-18
    • 2017-12-07
    • 2017-08-02
    相关资源
    最近更新 更多