Kivy Flatbutton 抛出弱引用错误
Kivy Flatbutton throwing a weak Reference Error
我的应用程序在 Flat_button 的 on_release 函数中抛出弱引用错误,我试图了解导致此问题的原因,但我真的不知道如何解决这个问题。我非常感谢任何见解。下面是我的日志和抛出错误的 admin.kv 文件。
日志
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 文件
#: 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 and here,解决方案是在window的开头添加__safe_id: [dropdown.__self__]
。
我的应用程序在 Flat_button 的 on_release 函数中抛出弱引用错误,我试图了解导致此问题的原因,但我真的不知道如何解决这个问题。我非常感谢任何见解。下面是我的日志和抛出错误的 admin.kv 文件。
日志
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 文件
#: 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 and here,解决方案是在window的开头添加__safe_id: [dropdown.__self__]
。