Kivy Flatbutton抛出弱引用错误



我的应用程序在Flat_button的on_rerelease函数中抛出了一个弱引用错误,我正试图了解是什么导致了这个错误,但我真的不知道如何解决这个问题。我非常感谢您的真知灼见。下面是我的日志和引发错误的admin.kv文件。

日志

File "C:UsersJohnPycharmProjectsFirstKivyApplicationPdminadmin.kv", line 31, in <module>
on_release: file_dropdown.open(self)
File "kivyweakproxy.pyx", line 32, in kivy.weakproxy.WeakProxy.__getattr__
File "kivyweakproxy.pyx", line 28, in kivy.weakproxy.WeakProxy.__ref__
ReferenceError: weakly-referenced object no longer exists

ADMIN.KV文件

#: 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)

根据here和here,解决方案是在窗口的开头添加__safe_id: [dropdown.__self__]

相关内容

  • 没有找到相关文章

最新更新