简体   繁体   English

'super' object 在 kivymd 中没有属性 '__getattr__'

[英]'super' object has no attribute '__getattr__' in kivymd

I wrote a kiwi app that has two pages.我写了一个有两页的猕猴桃应用程序。 The first page contains only one button to go to the next page.第一页只包含一个按钮到下一页 go。 The second page is a list of icons and titles.第二页是图标和标题列表。 It worked well when the app had a page, but I get an error adding the first page as a menu.当应用程序有一个页面时,它运行良好,但是将第一页添加为菜单时出现错误。 How can I solve it?我该如何解决? The error is for line 51 that I specified.错误是针对我指定的第 51 行。 Error: 'super' object has no attribute '__getattr__'错误: 'super' object has no attribute '__getattr__'

from kivy.lang import Builder
import glob
from kivymd.app import MDApp
from kivymd.uix.list.list import  TwoLineAvatarListItem
from kivymd.uix.list.list import ImageLeftWidget
from kivy.uix.screenmanager import ScreenManager, Screen

KV = '''
ScreenManager:
    MenuScreen:
    CoinScreen:
<MenuScreen>:
    name:"menu"
    MDRoundFlatButton:
        text: "SelectCoin"
        pos_hint: {"center_x": .2, "center_y": .8}
        on_press: root.manager.current = 'select_coin'

<CoinScreen>:
    name:"select_coin"
    ScrollView:
        MDList:
            id: text_container
            
'''
class MenuScreen(Screen):
    pass


class CoinScreen(Screen):
    pass

sm = ScreenManager()
sm.add_widget(MenuScreen(name='main'))
sm.add_widget(CoinScreen(name='select_coin'))


class Test(MDApp):
    def build(self):
        return Builder.load_string(KV)

    def on_start(self):
        icon_path = glob.glob("icon/*.png")
        for _ in range(len(icon_path)):
            icon_path[_]=icon_path[_].replace("\\","//")
        
        for i in icon_path:
            icons = ImageLeftWidget(source=i)
            items = TwoLineAvatarListItem(text=i + ' item',secondary_text= "Secondary text here")
            items.add_widget(icons)
            self.root.ids.text_container.add_widget(items) #**********error**********


Test().run()

You are trying to access the text_container id in the App , but that id is in the CoinScreen , not in the App .您正在尝试访问App中的text_container id,但该 id 位于CoinScreen中,而不是App中。 You can adjust the on_start() method to access the CoinScreen , like this:您可以调整on_start()方法以访问CoinScreen ,如下所示:

class Test(MDApp):
    def build(self):
        return Builder.load_string(KV)

    def on_start(self):
        icon_path = glob.glob("icon/*.png")
        for _ in range(len(icon_path)):
            icon_path[_] = icon_path[_].replace("\\", "//")

        coin_screen = MDApp.get_running_app().root.get_screen('select_coin')
        for i in icon_path:
            icons = ImageLeftWidget(source=i)
            items = TwoLineAvatarListItem(text=i + ' item', secondary_text="Secondary text here")
            items.add_widget(icons)
            coin_screen.ids.text_container.add_widget(items)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 kivymd: AttributeError: 'super' object 没有属性 '__getattr__' - kivymd: AttributeError: 'super' object has no attribute '__getattr__' AttributeError:“超级”对象没有属性“ __getattr__” - AttributeError: 'super' object has no attribute '__getattr__' KivyMD:“超级”对象在基于条件的屏幕转换期间没有属性“__getattr__” - KivyMD: 'super' object has no attribute '__getattr__' during screen transition based on condition AttributeError: &#39;super&#39; 对象在 kivymd 请求应用程序中没有属性 &#39;__getattr__&#39; 错误 - AttributeError: 'super' object has no attribute '__getattr__' error at kivymd request app AttributeError:“超级”对象没有属性“ __getattr __”(我进行了搜索,但无济于事) - AttributeError: 'super' object has no attribute '__getattr__' ( I searched, but to no avail) &#39;super&#39;对象在python3中没有属性&#39;__getattr__&#39; - 'super' object has no attribute '__getattr__' in python3 AttributeError: &#39;super&#39; 对象在 python 中没有属性 &#39;__getattr__&#39; - AttributeError: 'super' object has no attribute '__getattr__' in python Kivy: AttributeError: 'super' object 没有属性 '__getattr__' - Kivy: AttributeError: 'super' object has no attribute '__getattr__' Kivy AttributeError: 'super' object 没有属性 '__getattr__' - Kivy AttributeError: 'super' object has no attribute '__getattr__' Kivy AttributeError: 'super' object has no attribute '__getattr__' 错误 - Kivy AttributeError: 'super' object has no attribute '__getattr__' error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM