AttributeError: 'super' object has no attribute '__getattr__' in .kv
AttributeError: 'super' object has no attribute '__getattr__' in .kv
所以我正在使用 .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()
当我点击“清除字段”按钮时它抛出了这个错误
AttributeError: 'super' object has no attribute '__getattr__'
你的 ids
不应该是字符串。例如,更改:
TextInput:
id:"n"
至:
TextInput:
id: n
另一个类似 TextInputs
。
所以我正在使用 .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()
当我点击“清除字段”按钮时它抛出了这个错误
AttributeError: 'super' object has no attribute '__getattr__'
你的 ids
不应该是字符串。例如,更改:
TextInput:
id:"n"
至:
TextInput:
id: n
另一个类似 TextInputs
。