[英]'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.