属性错误:'super'对象在 .kv 中没有属性'__getattr__'



所以我正在使用。kv文件并尝试尝试文本输入然后我想清除文本输入所以我写了这段代码

Python

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.lang import Builder
from kivy.uix.textinput import TextInput
Builder.load_file("my.kv")
class MyLayout(Widget):
def __init__(self,**kwargs):
super(MyLayout,self).__init__(**kwargs)
def clear(self):
self.ids.n.text = ""
self.ids.fp.text = ""
self.ids.d.text = ""

class AwesomeApp(App):
def build(self):
return MyLayout()
if __name__ == '__main__':
AwesomeApp().run()

.kv

<Button>
font_size:20
<TextInput>
font_size:20
<Label>
font_size:20
<MyLayout>
BoxLayout:
orientation:"vertical"
size: root.width,root.height
padding:10
spacing:10
Label:
text:"Name"
TextInput:
id:"n"
multiline:False
Label:
text:"favorite Pizza"
TextInput:
id:"fp"
multiline:False
Label:
text:"Drinks"
TextInput:
id:"d"
multiline:False
Button:
text:"Submit"
Button:
text:"clear fields"
on_press:root.clear()

当我点击"清除字段&quot时,它会弹出这个错误;按钮

AttributeError: 'super' object has no attribute '__getattr__'

您的ids不应该是字符串。例如,修改:

TextInput:
id:"n"

:

TextInput:
id: n

其他TextInputs类似。

相关内容

  • 没有找到相关文章

最新更新