Referenceerror: Weakly-referenced Object No Longer Exists Kivy Dropdown
Solution 1:
In child widget, CustomDropDown
With on_parent: self.dismiss()
When you clicked on the main button, Menu name sometimes it gives an error, ReferenceError: weakly-referenced object no longer exists. If there is no ReferenceError, the drop-down list flash (appear and quickly disappear). The reason is that the DropDown was dismissed.
Without on_parent: self.dismiss()
It will display the CustomDropDown list at app startup. When the main button, Menu name is clicked, the drop-down list that appeared at startup disappeared but it displayed a drop-down list twice as long i.e. submenu items repeated twice.
Note
Drop-Down List is similar to Popup. They are special widget. Don't try to add it as a child to any other widget. If you do, they will be handled like an ordinary widget and won't be created hidden in the background.
Please refer to the example below illustrating how to create Drop-Down list.
Example
main.py
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.dropdown import DropDown
from kivy.core.window import Window
Window.size = (800, 480)
classCustomDropDown(DropDown):
passclassNotes(Screen):
passclassMyScreenManager(ScreenManager):
passclassTestApp(App):
title = "Kivy Drop-Down List Demo"defbuild(self):
return MyScreenManager()
if __name__ == '__main__':
TestApp().run()
test.kv
#:kivy 1.10.0#:import Factory kivy.factory.Factory<CustomDropDown>:on_select:app.root.ids.Notes.ids.mainbutton.text='{}'.format(args[1])Button:id:button1text:'First Item'size_hint_y:Noneheight:40font_size:18on_release:root.select(self.text)Button:id:button2text:'Second Item'size_hint_y:Noneheight:40font_size:18on_release:root.select(self.text)Button:id:button3text:'Third Item'size_hint_y:Noneheight:40font_size:18on_release:root.select(self.text)<MyScreenManager>:canvas.before:Color:rgba:0.5,0.5,0.5,0.5Rectangle:pos:0,0size:800,480Notes:id:Notesname:'Notes'<Notes>:orientation:"vertical"FloatLayout:size_hint:None,Nonecanvas.before:Color:rgba:1,1,0,1Button:id:mainbuttontext:"Menu name"font_size:20size_hint:None,Nonesize:150,50pos:20,400on_release:Factory.CustomDropDown().open(self)
Output
Solution 2:
from : $Yourkivydir/kivy-examples/demo/showcase/data/screens
ShowcaseScreen:fullscreen:Truename:'DropDown'# trick to not lost the Dropdown instance# Dropdown itself is not really made to be used in kv.__safe_id: [dropdown.__self__]
Button:id:btntext:'-'on_release:dropdown.open(self)size_hint_y:Noneheight:'48dp'Widget:on_parent:dropdown.dismiss()DropDown:id:dropdownon_select:btn.text='Selected value: {}'.format(args[1])Button:text:'Value A'size_hint_y:Noneheight:'48dp'on_release:dropdown.select('A')Button:text:'Value B'size_hint_y:Noneheight:'48dp'on_release:dropdown.select('B')Button:text:'Value C'size_hint_y:Noneheight:'48dp'on_release:dropdown.select('C')
Post a Comment for "Referenceerror: Weakly-referenced Object No Longer Exists Kivy Dropdown"