猕猴桃弹出问题。如何使弹出窗口显示在kivy模块上?

时间:2019-08-04 20:35:36

标签: python kivy

我正在尝试使用python和kivy文件打开弹出窗口。它说我的Boxlayout对象没有属性'open_popup'

这是我的python代码:

from kivy.app import App
from kivy.properties import BooleanProperty, ListProperty
from kivy.modules import inspector
from kivy.core.window import Window
from kivy.uix.popup import Popup


class CustomPopup(Popup):
    pass


class MPMS(App):
    def build(self):
        inspector.create_inspector(Window, self)

    def show_config_popup(self, popup):
        pass

    def open_popup(self):
        the_popup = CustomPopup()
        the_popup.open()


if __name__ == '__main__':
    app = MPMS()
    app.run()    

这是我的猕猴桃

BoxLayout:
    orientation: 'vertical'
    Label:
        text: 'MPMS'
    BoxLayout:
        orientation: 'horizontal'
        size_hint: (1, 0.25)
        BoxLayout:
            orientation: 'vertical'
            Button:
                id: 'screening_button_mainmenu'
                text: 'Screening'
        BoxLayout:
            orientation: 'vertical'
            Button:
                id: 'configuration_button_mainmenu'
                text: 'Configuration'
                on_press: root.open_popup()

<CustomPopup>:
    size_hint: .5, .5
    auto_dismiss: False
    title: "The Popup"
    BoxLayout:
        orientation: 'horizontal'
        Label:
            text: 'popup has appeared'

我尝试在youtube上查找视频,但没有,但是我看不到它对我有帮助,因为我无法将其应用于自己的情况。请帮帮我。预先感谢

1 个答案:

答案 0 :(得分:0)

那是因为您正在做on_press: root.open_popup(),在这种情况下,root是您的BoxLayout(该kv规则的根)。你想要的是

on_press: app.open_popup()

因为open_popup()中包含App方法。