英文:
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:
<GridLayout>
cols: 2
rows: 8
Label:
text: "name:"
row: 0
col: 0
TextInput:
id: name
multiline: False
row:0
col:1
on_text:
if len(self.text.strip()) >= 31: self.text = self.text[0:30]
Label:
text: "description:"
row: 1
col: 0
TextInput:
id: description
multiline: False
row:1
col:1
on_text:
if len(self.text.strip()) >= 100: self.text = self.text[0:99]
Spinner:
text: "hi"
values: ("hi1","hi2")
my python file:
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.spinner import Spinner
class SkinAssent(App):
def __init__(self, **kwargs):
super(SkinAssent, self).__init__(**kwargs)
def build(self):
return GridLayout()
def main():
SkinAssent().run()
if __name__ == '__main__':
main()
a window pops for a second up then I get this error:
File "C:\Usersmyrc\AppData\Local\Programs\Python\Python310\lib\site-packages\kivy\lang\builder.py", line 558, in _apply_rule
assert(rule not in self.rulectx)
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:
<GridLayout>
cols: 2
rows: 8
Label:
text: "name:"
row: 0
col: 0
TextInput:
id: name
multiline: False
row:0
col:1
on_text:
if len(self.text.strip()) >= 31: self.text = self.text[0:30]
Label:
text: "description:"
row: 1
col: 0
TextInput:
id: description
multiline: False
row:1
col:1
on_text:
if len(self.text.strip()) >= 100: self.text = self.text[0:99]
Spinner:
text: "hi"
values: ("hi1","h12")
my python file:
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.spinner import Spinner
class SkinAssent(App):
def __init__(self, **kwargs):
super(SkinAssent, self).__init__(**kwargs)
def build(self):
return GridLayout()
def main():
SkinAssent().run()
if __name__ == '__main__':
main()
a window pops for a second up then i get this error:
File "C:\Usersmyrc\AppData\Local\Programs\Python\Python310\lib\site-packages\kivy\lang\builder.py", line 558, in _apply_rule
assert(rule not in self.rulectx)
AssertionError
thanks, myrccar
答案1
得分: 1
我相信GridLayout
类存在某种冲突。尝试使用自定义类。您可以定义一个自定义类:
class MyGridLayout(GridLayout):
pass
然后在您的kv文件中使用该自定义类:
<MyGridLayout>:
cols: 2
rows: 8
Label:
以及在您的build()
方法中:
def build(self):
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:
class MyGridLayout(GridLayout):
pass
Then use that custom class in your kv
:
<MyGridLayout>
cols: 2
rows: 8
Label:
and in your build()
method:
def build(self):
return MyGridLayout()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论