致命Python错误:(pygame降落伞)分段错误中止

致命Python错误:(pygame降落伞)分段错误中止,python,pygame,kivy,Python,Pygame,Kivy,我正在尝试使用KivyGUI在python中制作一个杂货清单程序,点击一个按钮,我希望它向boxlayout添加一个自定义的floatlayout。floatlayout有一个复选框和一个标签。我一直收到这个错误致命的Python错误:(pygame降落伞)分段错误 当我运行它时中止,尽管下面是我的.py文件: from kivy.app import App from kivy.uix.label import Label from kivy.uix.button import Button

我正在尝试使用KivyGUI在python中制作一个杂货清单程序,点击一个按钮,我希望它向boxlayout添加一个自定义的floatlayout。floatlayout有一个复选框和一个标签。我一直收到这个错误致命的Python错误:(pygame降落伞)分段错误 当我运行它时中止,尽管下面是我的.py文件:

from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.checkbox import CheckBox
from kivy.uix.relativelayout import RelativeLayout
from kivy.uix.floatlayout import FloatLayout


class All(BoxLayout):

  def addIngredient(self):
    ing = Ingredient(name = self.ids.textInput.text)

    self.ids.list.add_widget(ListItem(ing))
    self.ids.button.text = 'done'

class ListItem(FloatLayout):

  def __init__(self, ing):
    self.ing = ing

class Ingredient():

  def __init__(self, name):
    self.name = name

class ListApp(App):
  def build(self):
    return All()

if __name__ == "__main__":

  ListApp().run()
这是我的.kv文件:

<All>:
  orientation: 'vertical'
  BoxLayout: 
    orientation: 'horizontal'
    TextInput:
      id: textInput
    Button:
      text: 'Add'
      on_press: root.addIngredient()
      id: button
  BoxLayout:
    orientation: 'vertical'
    id: list

<ListItem>:
  CheckBox:
    size_hint: 0.2, 1
  Label:
    size_hint: 0.35, 1
    text: ing.name
    halign: 'left'
   valign: 'middle'
我的猜测是,您的问题是由于覆盖ListItem的
\uuuuuu init\uuuuuuu
而不是调用超类
\uuuuuu init\uuuuu
;这是通常设置小部件内部的地方,因此当您尝试将小部件添加到某个对象时,您最终会遇到一个实例化不正确的小部件,从而导致问题

要解决此问题,请使用普通python方法调用超类方法:

class ListItem(FloatLayout):

    def __init__(self, ing):
        super(ListItem, self).__init__()
        self.ing = ing

不幸的是,这使得pygame只是一个错误。也许使用SDL2后端会出现一个更有用的错误。无论如何,您应该尝试将kivy 1.9与SDL2结合使用。

好的,我对Python和kivy非常熟悉,您能解释一下超级类init SLD2以及如何获得kivy 1.9吗?感谢您使用kivy网站上的说明下载kivy。对于类内容,googleit,这是与python对象结构交互的正常内容。
class ListItem(FloatLayout):

    def __init__(self, ing):
        self.ing = ing
class ListItem(FloatLayout):

    def __init__(self, ing):
        super(ListItem, self).__init__()
        self.ing = ing