How to dismiss the Kivy pop-up via a Button?

后端 未结 4 815
耶瑟儿~
耶瑟儿~ 2021-01-28 07:11

I have a pop-up created with Kivy, which contains 2 buttons. User can dismiss the pop-up by pressing outside of the pop-up area (auto_dismiss = True), or by clicking the \"No\"

相关标签:
4条回答
  • 2021-01-28 07:34

    Would something like this work in kivy?

    on_press : root.dismiss()
    
    0 讨论(0)
  • 2021-01-28 07:46

    Try this: on_press = self.popup.dismiss() in replacement of on_press = self.popup_exit.dismiss

    0 讨论(0)
  • 2021-01-28 07:48

    Change on_press = self.popup_exit.dismiss to on_press = lambda: self.popup_exit.dismiss() because dismiss is a function and needs to be called when the button is pressed.

    def exit_confirmation(self):
    
    
        # popup can only have one Widget.  This can be fixed by adding a BoxLayout
    
        self.box_popup = BoxLayout(orientation = 'horizontal')
    
        self.box_popup.add_widget(Label(text = "Really exit?"))
    
        self.box_popup.add_widget(Button(
            text = "Yes",
            on_press = ExitApp.exit,
            size_hint = (0.215, 0.075)))
    
        self.popup_exit = Popup(title = "Exit",
            content = self.box_popup,
            size_hint = (0.4, 0.4),
            auto_dismiss = True)
    
        self.box_popup.add_widget(Button(
        text = "No",
        on_press = lambda: self.popup_exit.dismiss() ,
        size_hint=(0.215, 0.075)))
    
        self.popup_exit.open()
    
    0 讨论(0)
  • 2021-01-28 07:53

    You can solve this issue by a lazy function

    on_press = lambda *args: self.popup_exit.dismiss()
    

    This way, the lookup will occur only when the button is pressed and popup_exit is already in place...

    0 讨论(0)
提交回复
热议问题