【问题标题】:Kivy POPUP and Button textKivy POPUP 和按钮文本
【发布时间】:2016-09-17 17:30:57
【问题描述】:

首先,我是 kivy 的新手。 myApp 基于kivy-example/demo/kivycatlog,我正在修改PopupContainer.kv,但我的代码不起作用。

PopupContainer.kv

BoxLayout:
    id: bl
    orientation: "vertical"
    popup: popup.__self__
    canvas:
        Color:
            rgba: .18, .18, .18, .91
        Rectangle:
            size: self.size
            pos: self.pos
    Button:
        id: showPopup1
        text: 'press to show popup'
        on_release: root.popup.open()
    Button:
        id: showPopup2
        text: 'press to show popup'
        on_release: root.popup.open()

Popup:
    id: popup
    on_parent: if self.parent == bl: bl.remove_widget(self)
    title: "An example popup"
    BoxLayout:
        orientation: 'vertical'
        BoxLayout:
            orientation: 'vertical'
            Button:
                id: accept
                text: "yes"
                on_release: status.text = self.text
            Button:
                id: cancel
                text: "no"
                on_release: status.text = self.text
            Label:
                id: status
                text: "yes or no?"
        Button:
            text: "press to dismiss"
            on_release: popup.dismiss()

当我点击“是”或“否”时,我想更改text(showPopup)showPopup的文字上。

【问题讨论】:

    标签: python kivy


    【解决方案1】:

    您可以从代码中获取 ShowPopup 按钮的文本。我的意思是在您的代码中声明一个名为popups_text 的变量,并在您的.kv 文件中尝试使用root.popups_text 访问它。然后在您的代码中创建一个方法,每次按下按钮时都会更改此文本。

    【讨论】:

    • 我不明白你的问题出在哪里
    猜你喜欢
    • 2020-08-05
    • 1970-01-01
    • 2016-06-07
    • 2013-02-26
    • 1970-01-01
    • 2013-09-29
    • 2022-01-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多