Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
285 views
in Technique[技术] by (71.8m points)

python - Reference error:Weakly referenced objects no longer exists error in KivyMd when using OneLineListItem

When I am running my application made with kivymd it is showing the error when I am using OneLineListItem ,and When I am removing it,so the application is running smoothly.I am using Python version 3.8.And when I am putting OneLineListItem after ScrollView,MDList in MyList Block so it is giving the error.When I written another code with only mdlist with onelinelistitem so it was running,please solve this issue. This is what log says-

ReferenceError: weakly-referenced object no longer exists. This is the code-

from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager,Screen
from kivy.uix.boxlayout import BoxLayout
from kivymd.uix.list import OneLineListItem
from kivymd.uix.navigationdrawer import NavigationLayout
KV='''
ScreenManager:
    Home:
    Submit:
<Home>:
    name:'home'
    NavigationLayout:
        ScreenManager:
            MDScreen:
                AnchorLayout:
                    anchor_x:'center'
                    anchor_y:'top'
                    MDToolbar:
                        id:toolbar
                        title:'My Register'
                        md_bg_color:app.theme_cls.primary_dark
                        height:'75dp'
                        left_action_items:[['menu',lambda x:navi_draw.set_state()]]
                        elevation:10
                    MDScreen:
                        MDTextField:
                            id:student_name
                            hint_text:'Enter student name'
                            helper_text:'Should only contain alphabetical literals'
                            helper_text_mode:'on_focus'
                            pos_hint:{'center_x':0.5,'center_y':0.5}
                            size_hint_x:None
                            width:460
                            icon_right:'face'
                            icon_right_color:app.theme_cls.primary_color
                        MDRaisedButton:
                            text:'Submit'
                            pos_hint:{'center_x':0.5,'center_y':0.4}
                            
                            on_press:
                                
                                root.manager.current='submit'
    
                                root.manager.transition.direction = 'left'
                            
        MDNavigationDrawer:
            id:navi_draw 
         
            BoxLayout:
                oreintation:'vertical'      
                
               
                   
                MyList:
                    id:list                                 
                                 
                                 
                                 
                
                    
<MyList>:
    oreintation:'vertical'
    padding: "1dp"
    spacing: "1dp"
    AnchorLayout:
        anchor_x: "left"
        size_hint_y: None
        height: avatar.height

    Image:
        id: avatar
        size_hint: None, None
        size: "300dp", "300dp"
        source: "vishu.jpg"
        
        pos_hint:{'center_x':0.5,'center_y':0.9}
    ScrollView:
        MDList:
            OneLineListItem:
                                                                                                        
                                                    
                                                    
                    
<ItemDrawer>:
                                                             
<Submit>:
    name:'submit'
    MDLabel:
        text:'Submitted'
        halign:'center'
        font_style:'H3'
    MDIconButton:
        icon:'arrow-left'
        on_press:
            root.manager.current='home'
            root.manager.transition.direction = 'right'
'''
class MyList(BoxLayout):
    pass 
class ItemDrawer(OneLineListItem):
    pass
class Home(Screen):
    pass
class Submit(Screen):
    pass
sm=ScreenManager()
sm.add_widget(Home(name="home"))
sm.add_widget(Submit(name="submit"))

class MyApp(MDApp):
    def build(self):
        self.theme_cls.primary_palette = "Teal" 

        screen=Screen()
        
        tool=Builder.load_string(KV)
        screen.add_widget(tool)
        return screen                
MyApp().run()       
question from:https://stackoverflow.com/questions/65856444/reference-errorweakly-referenced-objects-no-longer-exists-error-in-kivymd-when

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Weakly-referenced object no longer exists basically happens when you are trying to access a temporary variable defined within a class again and again. Every temporary variable has a limit up to how many times it can be called, after that it no longer exists. To make a variable exist more than that you have to use self. in front of it. So just check which part is causing the error and define variables in that part using self.. Also, one more important thing, there's a bug in earlier versions of kivy which causes this issue. So if you are using an older version then, first of all, update it. Make sure it's the latest version for both kivy and kivymd.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...