在弹出窗口中添加多个按钮 window

adding multiple buttons in a popup window

我创建了一个弹出窗口 window。通常我们使用pop.dismiss来关闭弹窗。但我想在该弹出窗口中添加一些按钮。我有 4 个按钮。当按下其中两个按钮时,它们应该显示另一个小部件(boxlayout)。 但是当我触摸这些按钮时,应用程序崩溃了。

但是,这 4 个按钮中的其他 2 个在触摸时会显示另一个弹出窗口 window。运行良好,不会崩溃。

  1. 从弹出窗口 window>触摸按钮>显示另一个弹出窗口 window > 没有崩溃
  2. 从弹出窗口>按钮这 4 个按钮中的任何一个>为了显示 boxlayout 小部件>应用程序崩溃了!

有人可以解释一下吗?我应该如何解决这个问题?

(.py) 文件

    class abc(Popup):   

        def about_app(self):
            self.clear_widgets()
            self.add_widget(about())    

        def about_leo(self):
            self.clear_widgets()
            self.add_widget(page1())

        def help(self):
            pops=help_popup()
            pops.open() 

        def website(self):
            pops=website()
            pops.open()

(.kv) 文件

<abc>:  
    title: 'LEO CLUB'
    title_color: 1, 0, 0, 1 
    title_size: 50
    title_align:'center'
    background: 'popup.png'
    size_hint: .6, 0.8
    pos_hint: {'right': .6, 'top': 1}

    BoxLayout:          
        BoxLayout:
            orientation:'vertical'                      

            Button:
                bold: True
                text: "About LEO"
                background_color: 0, 0, 0, 0
                on_release: root.about_leo()
            Button:
                bold:True
                text: "About App"
                background_color: 0, 0, 0, 0
                on_release: root.about_app()                                                 
            Button:
                bold: True
                text: "Website"
                background_color: 0, 0, 0, 0
                on_release: root.website()
            Button:
                bold: True
                text: "Help"
                background_color: 0, 0, 0, 0
                on_release: root.help()

您的代码在 abc class(这是一个 Popup)中调用 self.add_widget(),但是一个 Popup 只能有一个 child(它是 content)。对 clear_widgets() 的调用删除了 Popup 的所有 children,但不会更改 content 属性(它可能应该)。所以即使你已经删除了Popupchildren,它仍然认为它有一个non-emptycontent。所以,您真正需要做的只是设置新的 content。在您的 abc class 中,只需将这两个方法替换为:

def about_app(self):
    self.content = about()

def about_leo(self):
    self.content = page1()