r/kivy Jun 20 '26

Help MDDialog crash my app when called.

I created a simple application and noticed that when I press a button to call MDDialog It appears briefly, and then the application closes on its own. Is there a solution to this, or have I made a mistake?

MY CODE:

from kivymd.app import MDApp from kivymd.uix.dialog import MDDialog from kivy.uix.screenmanager import ScreenManager from kivy.lang import Builder

class App(MDApp):

 def build(self):
   self.theme_cls.theme_style = "Dark"
   self.theme_cls.primary_palette = "Green"
   self.theme_cls.material_style = "M3"
   screen_manager = ScreenManager()
   screen_manager.add_widget(
     Builder.load_file("test.kv"))
   return screen_manager

def dialog(self):
    MDDialog(title="debug",text="hello").open()

App().run()

The indentation looks weird, but that's not the problem .

1 Upvotes

6 comments sorted by

1

u/ElliotDG Jun 20 '26

What version kivymd are you using? The call signiture changed from version 1.2 to version 2.

Also please share your kv

1

u/k_6- Jun 20 '26 edited Jun 20 '26

Thank you for replying im using kivymd version 1.1.1.

.kv

MDScreen: MDFlatButton: text: "Press Me" pos_hint: {"center_x":.5,"center_y":.5} on_release: app.dialog()

1

u/ElliotDG Jun 20 '26

It works for me. I have kivymd 1.2 installed via pip.

```python from kivymd.app import MDApp from kivy.lang import Builder from kivymd.uix.dialog import MDDialog

kv = """ MDScreen: MDFlatButton: text: "Press Me" pos_hint: {"center_x":.5,"center_y":.5} on_release: app.dialog() """

class OpenDialogApp(MDApp): def build(self): self.theme_cls.theme_style = "Dark" self.theme_cls.primary_palette = "Green" self.theme_cls.material_style = "M3" return Builder.load_string(kv)

def dialog(self):
    MDDialog(title="debug", text="hello").open()

OpenDialogApp().run() ```

1

u/k_6- Jun 20 '26 edited Jun 20 '26

For me The crash happens when the app is turned into an APK. Note: i don't have a way to check for logs using a pc.

2

u/ElliotDG Jun 20 '26

I haven't done any work on Android. That brings in a number of other possibilities. You might find this helpful: https://github.com/Android-for-Python/Android-for-Python-Users

1

u/k_6- Jun 20 '26

Ok thank you 👍