gpt4 book ai didi

python - kivy 弹出问题。如何让弹出窗口显示在 kivy 模块上?

转载 作者:太空宇宙 更新时间:2023-11-03 20:33:13 27 4
gpt4 key购买 nike

我正在尝试让我的 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()

这是我的 kivy

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 等上查找视频,但我看不到它对我有帮助,因为我无法将其应用于我的情况。请帮帮我。提前致谢

最佳答案

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

on_press: app.open_popup()

因为 open_popup() 方法位于您的 App 中。

关于python - kivy 弹出问题。如何让弹出窗口显示在 kivy 模块上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57350057/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com