spinner widget crashes my kivy app on start

huangapple go评论97阅读模式
英文:

spinner widget crashes my kivy app on start

问题

I was working on a kivy(2.1.0) and added a spinner widget when I tried to run the app it crashed on startup. it works without the spinner widget. my code:

the .kv file:

  1. <GridLayout>
  2. cols: 2
  3. rows: 8
  4. Label:
  5. text: "name:"
  6. row: 0
  7. col: 0
  8. TextInput:
  9. id: name
  10. multiline: False
  11. row:0
  12. col:1
  13. on_text:
  14. if len(self.text.strip()) >= 31: self.text = self.text[0:30]
  15. Label:
  16. text: "description:"
  17. row: 1
  18. col: 0
  19. TextInput:
  20. id: description
  21. multiline: False
  22. row:1
  23. col:1
  24. on_text:
  25. if len(self.text.strip()) >= 100: self.text = self.text[0:99]
  26. Spinner:
  27. text: "hi"
  28. values: ("hi1","hi2")

my python file:

  1. from kivy.app import App
  2. from kivy.uix.gridlayout import GridLayout
  3. from kivy.uix.textinput import TextInput
  4. from kivy.uix.button import Button
  5. from kivy.uix.spinner import Spinner
  6. class SkinAssent(App):
  7. def __init__(self, **kwargs):
  8. super(SkinAssent, self).__init__(**kwargs)
  9. def build(self):
  10. return GridLayout()
  11. def main():
  12. SkinAssent().run()
  13. if __name__ == '__main__':
  14. main()

a window pops for a second up then I get this error:

  1. File "C:\Usersmyrc\AppData\Local\Programs\Python\Python310\lib\site-packages\kivy\lang\builder.py", line 558, in _apply_rule
  2. assert(rule not in self.rulectx)
  3. AssertionError

Thanks, myrccar

英文:

I was working on a kivy(2.1.0) and added a spinner widget when I tried to run the app it crashed on startup. it works without the spinner widget. my code:

the .kv file:

  1. &lt;GridLayout&gt;
  2. cols: 2
  3. rows: 8
  4. Label:
  5. text: &quot;name:&quot;
  6. row: 0
  7. col: 0
  8. TextInput:
  9. id: name
  10. multiline: False
  11. row:0
  12. col:1
  13. on_text:
  14. if len(self.text.strip()) &gt;= 31: self.text = self.text[0:30]
  15. Label:
  16. text: &quot;description:&quot;
  17. row: 1
  18. col: 0
  19. TextInput:
  20. id: description
  21. multiline: False
  22. row:1
  23. col:1
  24. on_text:
  25. if len(self.text.strip()) &gt;= 100: self.text = self.text[0:99]
  26. Spinner:
  27. text: &quot;hi&quot;
  28. values: (&quot;hi1&quot;,&quot;h12&quot;)

my python file:

  1. from kivy.app import App
  2. from kivy.uix.gridlayout import GridLayout
  3. from kivy.uix.textinput import TextInput
  4. from kivy.uix.button import Button
  5. from kivy.uix.spinner import Spinner
  6. class SkinAssent(App):
  7. def __init__(self, **kwargs):
  8. super(SkinAssent, self).__init__(**kwargs)
  9. def build(self):
  10. return GridLayout()
  11. def main():
  12. SkinAssent().run()
  13. if __name__ == &#39;__main__&#39;:
  14. main()

a window pops for a second up then i get this error:

  1. File &quot;C:\Usersmyrc\AppData\Local\Programs\Python\Python310\lib\site-packages\kivy\lang\builder.py&quot;, line 558, in _apply_rule
  2. assert(rule not in self.rulectx)
  3. AssertionError

thanks, myrccar

答案1

得分: 1

我相信GridLayout类存在某种冲突。尝试使用自定义类。您可以定义一个自定义类:

  1. class MyGridLayout(GridLayout):
  2. pass

然后在您的kv文件中使用该自定义类:

  1. <MyGridLayout>:
  2. cols: 2
  3. rows: 8
  4. Label:

以及在您的build()方法中:

  1. def build(self):
  2. return MyGridLayout()
英文:

I believe there is some kind of conflict with the GridLayout class. Try using a custom class. You can define a custom class:

  1. class MyGridLayout(GridLayout):
  2. pass

Then use that custom class in your kv:

  1. &lt;MyGridLayout&gt;
  2. cols: 2
  3. rows: 8
  4. Label:

and in your build() method:

  1. def build(self):
  2. return MyGridLayout()

huangapple
  • 本文由 发表于 2023年2月10日 07:09:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/75405407.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定