Search code examples
pythonpycharmkivy-languageweak-references

Kivy Flatbutton throwing a weak Reference Error


My application is throwing a weak reference error in the on_release function of Flat_button and am trying to understand what is causing this but I really cant figure out how to solve this. I highly appreciate any insights. Below are my logs and admin.kv file which is throwing the error.

THE LOGS

   File "C:\Users\John\PycharmProjects\FirstKivyApplication\Pdmin\admin.kv", line 31, in <module>
     on_release: file_dropdown.open(self)
   File "kivy\weakproxy.pyx", line 32, in kivy.weakproxy.WeakProxy.__getattr__
   File "kivy\weakproxy.pyx", line 28, in kivy.weakproxy.WeakProxy.__ref__
 ReferenceError: weakly-referenced object no longer exists

ADMIN.KV FILE

#: import Window kivy.core.window.Window

<FlatButton@ButtonBehavior+Label>:
    text: 'default'

<AdminWindow>:

    id: main_win
    orientation: 'vertical'
    canvas.before:
        Color:
            rgba: (1,1,1,1)
        Rectangle:
            size: self.size
            pos: self.pos


  BoxLayout:
        id: top_nav
        size_hint_y: None
        height: 30
        canvas.before:
            Color:
                rgba: (.06, .45, .45,1)
            Rectangle:
                size: self.size
                pos: self.pos

        FlatButton:
            id: file_trigger
            text: 'File'
            on_release: file_dropdown.open(self)
            size_hint: (.1,None)
            height: 30

            Widget:
                on_parent: file_dropdown.dismiss()

                DropDown:
                    id: file_dropdown

                    Button:
                        id: close
                        text: 'Logout'
                        size_hint_y: None
                        height: 30
                        on_release: root.logout()

                    Button:
                        id: close
                        text: 'Quit'
                        size_hint_y: None
                        height: 30
                        on_release: root.Window.close()
        Label:
            text: 'Admin Dashboard'
            bold: True
            size_hint: (.9,None)

Solution

  • According to here and here, the solution is to add __safe_id: [dropdown.__self__] at the beginning of the window.