Is there a way to prevent an Mddialog widget from closing?

48 views Asked by At

I make a box that appears when I click on a button. I want it to closed only when I click on the buttons that are displayed on that box. But it's still closed when I click somewhere else.

I make an interface that contains a button. And when I click on the button it open a box that contains 3 buttons. I created this box using a kivymd Mddialog widget. When I click on one of these 3 buttons it dismiss the box. But the problem is that when I click somewhere else, the box is also dismissed. So I want the box to be dismissed only when I click on the the buttons that are displayed in the box, and to keep open when I click somewhere else.

Here is my python code



from kivymd.app import MDApp 

from kivy.uix.boxlayout import BoxLayout 

from kivymd.uix.screen import MDScreen

from kivymd.uix.screenmanager import MDScreenManager 

from kivy.uix.gridlayout import GridLayout 

from kivymd.uix.dialog import MDDialog

from kivymd.uix.button import MDFloatingActionButton,MDFlatButton,MDRoundFlatButton

ref_help=None

class Interface(MDScreen):

    def show_help(self):

        global ref_help

        ref_help=Help()

        ref_help.open()

        

class Help(MDDialog):

    def close_help(self):

        global ref_help

        ref_help.dismiss()

class MyApp(MDApp):

    pass

MyApp().run()


Et voici le code kv

Interface:

<Interface>:

    MDScreen:

        name:"screen1"

        MDRoundFlatButton:

            id: start_button

            text:"START"

            font_size:70

            pos_hint:{"center_x":.5,"center_y":.22}

            on_press: root.show_help()

        

            

Here is the kV code

            

<Help>:

    md_bg_color:0,0,0,0

    radius:[dp(30),dp(30),dp(30),dp(30)]

    size_hint:.8,.2

    MDBoxLayout:

        radius:[dp(30),dp(30),dp(30),dp(30)]

        md_bg_color:1,1,0,.1

        orientation: "vertical"

        

        MDLabel:

            text:"help center"

            font_size: dp(30)

            halign:"center"

            pos_hint:{"top":1}

        

        MDBoxLayout:

            spacing: dp(5)

            pos_hint:{"center_x":.5}

            padding:dp(40),dp(1)

            

            MDIconButton:

                id: delete

                theme_text_color:"Custom"

                text_color:1,0,0,1

                icon:"delete"

                icon_size:dp(40)

                on_press: root.close_help()

            MDIconButton:

                id: equal

                theme_text_color:"Custom"

                text_color:1,0,0,1

                icon:"approximately-equal"

                icon_size:dp(40)

                on_press: root.close_help()

            MDIconButton:

                id: wifi

                theme_text_color:"Custom"

                text_color:1,0,0,1

                icon:"wifi"

                icon_size:dp(40)

                on_press: root.close_help()

1

There are 1 answers

0
Francis Newton On

I finally fixed the issues. In kivymd there is a property inside the Mddialog that called auto_dismiss. By default this property is set to True. In order to avoid the Mddialog to be closed when you click somewhere else you just have to turn this property into False.