Python KIVY错误:AttributeError:&x27;超级';对象没有属性'__getattr';
我不熟悉这种编程,我正在尝试解决这个错误(python 3,在PyCharm上运行): 本项目未来将使用对项目实际状态不有用的所有部分 #######奇维锉刀Python KIVY错误:AttributeError:&x27;超级';对象没有属性'__getattr';,python,class,kivy,kivy-language,super,Python,Class,Kivy,Kivy Language,Super,我不熟悉这种编程,我正在尝试解决这个错误(python 3,在PyCharm上运行): 本项目未来将使用对项目实际状态不有用的所有部分 #######奇维锉刀 : 莉斯塔:莉斯塔 方向:“垂直” 输入:root.set\u data() 标签: 正文:“主要” 回收审查: viewclass:“按钮” 循环利用布局: id:lista 默认大小:无,dp(56) 默认大小提示:1,无 方向:“垂直” 如果有人能解释这个问题,我会非常感激。几个问题: 您的lista属性附加到kv中的错误项。它
:
莉斯塔:莉斯塔
方向:“垂直”
输入:root.set\u data()
标签:
正文:“主要”
回收审查:
viewclass:“按钮”
循环利用布局:
id:lista
默认大小:无,dp(56)
默认大小提示:1,无
方向:“垂直”
如果有人能解释这个问题,我会非常感激。几个问题:
- 您的
属性附加到lista
中的错误项。它应该附加到kv
,而不是回收视图
回收布局
- 必须为
包含RecycleBoxLayout
属性height
kv
的更新版本:
<MainWindow>:
lista: lista
on_enter: root.set_data()
Label:
text: "main"
RecycleView:
id: lista
viewclass: 'Button'
RecycleBoxLayout:
default_size: None, dp(56)
default_size_hint: 1, None
size_hint_y: None
height: self.minimum_height
orientation: 'vertical'
<MainWindow>:
lista: lista
on_enter: root.set_data()
Label:
text: "main"
RecycleView:
id: lista
viewclass: 'Button'
RecycleBoxLayout:
default_size: None, dp(56)
default_size_hint: 1, None
size_hint_y: None
height: self.minimum_height
orientation: 'vertical'
这并没有完全起作用,事实上我现在得到了这个错误:
Exception: Invalid instance in App.root
这是更新的代码:
from kivy.lang import Builder
from kivy.properties import ObjectProperty
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.popup import Popup
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.factory import Factory
from kivy.properties import ObjectProperty
from kivy.uix.recycleview import RecycleView
from kivy.uix.recycleboxlayout import RecycleBoxLayout
import os
os.chdir("C:\\Users\\Davide\\PycharmProjects\\RUBRICA")
first_imp = False
class Introduction1Window(Screen):
def go_to_int2(self):
application.sm.current = application.screens[2].name
class Introduction2Window(Screen):
file_chooser: ObjectProperty(None)
dir = "C:\\Program Files"
def go_to_main(self):
application.sm.switch_to(application.screens[0])
def set_dir(self):
self.dir = self.file_chooser.path
#class NewContact(Screen):
#pass
#class ModContact(Screen):
#àpass
class MainWindow(Screen):
lista = ObjectProperty(None)
def set_data(self,*args):
self.lista.data = [{'text=': str(x)} for x in range(30)]
class WindowManager(ScreenManager):
pass
class Main(App):
sm = None
screens = [MainWindow(name="MainWindow"),Introduction1Window(name="Introduction1Window"),Introduction2Window(name="Introduction2Window")]
def build(self):
self.sm = WindowManager()
for screen in self.screens:
self.sm.add_widget(screen)
if first_imp:
self.sm.current = "Introduction1Window"
else:
self.sm.current = "MainWindow"
return self.sm.current
application = Main()
application.run()
KIVY文件:
:
莉斯塔:莉斯塔
输入:root.set\u data()
标签:
正文:“主要”
回收审查:
id:lista
viewclass:“按钮”
循环利用布局:
默认大小:无,dp(56)
默认大小提示:1,无
尺寸提示:无
高度:自身最小高度
方向:“垂直”
class MainWindow(Screen):
lista = ObjectProperty(None)
def set_data(self, *args):
self.lista.data = [{'text': str(x)} for x in range(30)]
Exception: Invalid instance in App.root
from kivy.lang import Builder
from kivy.properties import ObjectProperty
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.popup import Popup
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.factory import Factory
from kivy.properties import ObjectProperty
from kivy.uix.recycleview import RecycleView
from kivy.uix.recycleboxlayout import RecycleBoxLayout
import os
os.chdir("C:\\Users\\Davide\\PycharmProjects\\RUBRICA")
first_imp = False
class Introduction1Window(Screen):
def go_to_int2(self):
application.sm.current = application.screens[2].name
class Introduction2Window(Screen):
file_chooser: ObjectProperty(None)
dir = "C:\\Program Files"
def go_to_main(self):
application.sm.switch_to(application.screens[0])
def set_dir(self):
self.dir = self.file_chooser.path
#class NewContact(Screen):
#pass
#class ModContact(Screen):
#àpass
class MainWindow(Screen):
lista = ObjectProperty(None)
def set_data(self,*args):
self.lista.data = [{'text=': str(x)} for x in range(30)]
class WindowManager(ScreenManager):
pass
class Main(App):
sm = None
screens = [MainWindow(name="MainWindow"),Introduction1Window(name="Introduction1Window"),Introduction2Window(name="Introduction2Window")]
def build(self):
self.sm = WindowManager()
for screen in self.screens:
self.sm.add_widget(screen)
if first_imp:
self.sm.current = "Introduction1Window"
else:
self.sm.current = "MainWindow"
return self.sm.current
application = Main()
application.run()
<MainWindow>:
lista: lista
on_enter: root.set_data()
Label:
text: "main"
RecycleView:
id: lista
viewclass: 'Button'
RecycleBoxLayout:
default_size: None, dp(56)
default_size_hint: 1, None
size_hint_y: None
height: self.minimum_height
orientation: 'vertical'