【问题标题】:KIVY ERROR: Exception: ScrollView accept only one widgetKIVY 错误:异常:ScrollView 只接受一个小部件
【发布时间】:2020-11-19 23:01:38
【问题描述】:

我试图运行这个程序,但我得到了这个错误,我不知道它是什么意思。如果有人可以展示如何解决它,我将非常感激。 ################################################# 蟒蛇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()

############################################## ################一个 基维文件:

#: 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:

【问题讨论】:

    标签: python graphics kivy


    【解决方案1】:

    由于您已将kv 文件命名为main.kv,它将按照documentation 中的说明自动加载。但是,您也正在使用以下行加载同一个文件:

    kv = Builder.load_file("main.kv")
    

    多次加载相同的kv 文件可能会导致意外结果,您会看到这样的结果。您可以通过简单地删除上述行或更改 kv 文件的名称来避免您看到的错误。

    【讨论】:

      【解决方案2】:

      感谢您解决该问题,但现在我收到此错误:

       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__'
      

      我认为,正如人们所说,这是与数据加载有关的问题 (self.screens[0].ids.lista_di_dati.data = [{'text='+ str(x)} for x in range(30)])

      【讨论】:

      • 您需要提交一个单独的问题。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多