문제

I'm experimenting with kivy, I keep getting segmentation fault from following code and can't figure it out. I suspect there is something wrong with my understanding of classes in python.

By trial and error found commenting

#p.open()

Stops the problem, yet I cannot solve nor understand the error. Thanks

Error:

Fatal Python error: (pygame parachute) Segmentation Fault

Python code

class popper(Popup):
    yazi= StringProperty("notsetyet")

    def __init__(self, texty):
       self.yazi = text
       print texty


class boxxy(BoxLayout):
   ...
   def on_press(self):
      p = popper("test_value")
      p.open()       
   ...

.kv file

<popper>

    title: "Warn"
    size_hint: 0.5 , 0.5
    BoxLayout:
        orientation: 'vertical'
        Label:
            text:     root.yazi
        Button:
            text: "close"
            on_press: root.dismiss()
도움이 되었습니까?

해결책

I don't know exactly what's causing your problem, but there are multiple bugs in your code. Also, it's best if you can provide a full working minimal example, that makes it a lot easier to debug.

The main bug (that may well cause this) is that you don't call super(Popper, self).__init__(**kwargs) in your __init__ definition (which probably also needs to be defined with def __init__(texty, **kwargs) to catch extra arguments). This is vital because the normal __init__ sets up all the normal widget and popup behaviour.

You also have self.yazi = text when you mean self.yazi = texty.

Finally, it is a normal Python convention to have class names start with a capital letter. Although this is normally just a stylistic guide and not a requirement, I think kv language depends on it sometimes, so you may get crashes or strange behaviour if you don't do so.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top