我试图运行这个程序,但我遇到了这个错误,我不知道它意味着什么。如果有人能告诉我如何修理它,我将不胜感激。##################################################python 3.8关于pycharm
PYTHON文件:
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")
data_cont = []
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):
pass
class WindowManager(ScreenManager):
pass
kv = Builder.load_file("main.kv")
class Main(App):
sm = None
screens = [MainWindow(name="MainWindow"),Introduction1Window(name="Introduction1Window"),Introduction2Window(name="Introduction2Window(Screen)")]
kv = None
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"
self.screens[0].ids.lista_di_dati.data = [{'text='+ str(x)} for x in range(30)]
return self.sm
application = Main()
application.run()
###############################################################àKIVY文件:
#: include newcontact.kv
#: include modcontact.kv
#: include introductionwindows.kv
#: include labels.kv
##: include datalayout.kv
<RecViewCustom@RecycleView>:
viewclass: "Button"
RecycleBoxLayout:
id: 'lista_di_dati'
default_size: None, dp(56)
default_size_hint: 1, None
size_hint_y: 1
orientation: 'vertical'
MainWindow:
#on_enter: root.load_rec_view()
name: "MainWindow"
orientation: "vertical"
viewclass: "Label"
Label:
text: "main"
RecViewCustom:
<WindowManager>:
MainWindow:
NewContact:
ModContact:
由于您已将kv
文件命名为main.kv
,因此它将按照文档中的说明自动加载。然而,您也加载了相同的文件,行为:
kv = Builder.load_file("main.kv")
多次加载同一个kv
文件可能会导致意外的结果,而您正看到这样的结果。您可以通过简单地删除上面的行或更改kv
文件的名称来避免出现错误。
谢谢你解决了这个问题,但现在我收到了这个错误:
Traceback (most recent call last):
File "kivyproperties.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:...AppDataLocalProgramsPythonPython37libsite-packageskivyapp.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 "kivyproperties.pyx", line 863, in kivy.properties.ObservableDict.__getattr__
AttributeError: 'super' object has no attribute '__getattr__'
我认为,正如所说,这是一个与数据加载(self.screens[0].ids.lista_di_dati.data = [{'text='+ str(x)} for x in range(30)]
(有关的问题