【发布时间】:2020-10-06 15:52:03
【问题描述】:
我只是在做一个小项目并制作了多个屏幕(使用 kivy),在一个用户将输入他/她的体重和身高的屏幕中,我得到了一个 Attributeerror getattr。不知道我在代码中做错了什么。我是 python 新手,所以我需要帮助。
这里是python代码:
class UserHomeScrren(BoxLayout):
def __init__(self, **kwargs):
super(UserHomeScrren, self).__init__(**kwargs)
def calculate(self):
#weight =int(self.weight.text)
weight=int(self.ids.backdrop.ids.backlayer.bmi_screen.weight.text)
height= int (self.ids.backdrop.ids.backlayer.bmi_screen.height.text)
print(self.ids.backlayer.ids.bmi_screen.ids.height)
BMI = round((weight * 703) / (height ** 2))
if BMI < 18.5:
self.ids.results.text += "Your BMI is " + str(BMI) + " which means you are underweight."
def clear(self):
self.ids.results.text = ""
self.ids.weight.text = ""
self.ids.height.text = ""
print(weight)
print('calculate.....')
class ItemBackdropBackLayer(ThemableBehavior, BoxLayout):
icon = StringProperty("android")
text = StringProperty()
selected_item = BooleanProperty(False)
def on_touch_down(self, touch):
if self.collide_point(touch.x, touch.y):
for item in self.parent.children:
if item.selected_item:
item.selected_item = False
self.selected_item = True
return super().on_touch_down(touch)
class UserApp(MDApp):
def __init__(self, **kwargs):
self.title = "User Flana"
self.theme_cls.primary_palette = "DeepPurple"
super().__init__(**kwargs)
Window.size = (300, 550)
def __getattr__(self, attr):
return super().__getattr__(attr)
def build(self):
return UserHomeScrren()
if __name__ == "__main__":
UserApp().run()
这里是日志:
File "d:\obacity\userHome\user.py", line 38, in calculate
weight=int(self.ids.backdrop.ids.backlayer.bmi_screen.weight.text)
File "kivy\properties.pyx", line 863, in kivy.properties.ObservableDict.__getattr__
AttributeError: 'super' object has no attribute '__getattr__'```
【问题讨论】:
标签: python python-3.x python-2.7 kivy