【发布时间】:2020-11-20 08:15:18
【问题描述】:
我是这种编程的新手,我正在尝试解决这个错误(python 3,在 PyCharm 上运行):
Traceback (most recent call last):
File "kivy\properties.pyx", line 860, in kivy.properties.ObservableDict.__getattr__
KeyError: 'lista'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/...PycharmProjects/RUBRICA/main.py", line 62, in <module>
application.run()
File "C:\...AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\app.py", line 829, in run
root = self.build()
File "C:/...PycharmProjects/RUBRICA/main.py", line 57, in build
self.screens[0].ids.lista.data = [{'text='+ str(x)} for x in range(30)]
File "kivy\properties.pyx", line 863, in kivy.properties.ObservableDict.__getattr__
AttributeError: 'super' object has no attribute '__getattr__'
##########PY 文件:
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):
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()
self.icon = 'intbackgorund.png'
for screen in self.screens:
self.sm.add_widget(screen)
if first_imp:
self.sm.current = "Introduction1Window"
else:
self.sm.current = "MainWindow"
#self.screens[0].ids.lista.data = [{'text='+ str(x)} for x in range(30)]
return self.sm.current
application = Main()
application.run()
凡是对程序实际状态无用的部分,以后都会用到本项目中
#######KIVY 文件
<MainWindow>:
lista: lista
orientation: "vertical"
on_enter: root.set_data()
Label:
text: "main"
RecycleView:
viewclass: 'Button'
RecycleBoxLayout:
id: lista
default_size: None, dp(56)
default_size_hint: 1, None
orientation: 'vertical'
如果有人能解释这个问题,我会非常感激。
【问题讨论】:
标签: python class kivy kivy-language super