【问题标题】:AttributeError: 'super' object has no attribute '__getattr__' in kivy .kv fileAttributeError:“超级”对象在 kivy .kv 文件中没有属性“__getattr__”
【发布时间】:2021-08-19 16:32:05
【问题描述】:

不过,这太烦人了,kv-kivy-this-that-error,UHH...... 无论如何,我似乎没有得到 kivy,好的,我仍然在 .kv 文件中玩耍 并且烦人而迟缓地放弃了它的“典型”反应

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

我感到目瞪口呆,这是什么,为什么是 KIVY-无论如何我必须提供一些东西来展示真正发生的事情 蟒蛇

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.lang import Builder
from kivy.uix.textinput import TextInput
from kivy.uix.label import Label
Builder.load_file("my.kv")
class MyLayout(Widget,App):
    def __init__(self,*args,**kwargs):
        super(MyLayout, self).__init__(**kwargs)
    def clear(self):
        self.ids.n.text = ""
        self.ids.fp.text = ""
        self.ids.d.text = ""
    def writeD(self):
        name = self.ids.n.text
        pizza = self.ids.fp.text
        drinks = self.ids.d.text
        orders = open("order.txt","w")
        orders.write(f"Name: {name}\n")
        orders.write(f"Pizza: {pizza}\n")
        orders.write(f"Drinks: {drinks}")
    def read(self):
        orders = open("order.txt","r")
        orderL = orders.read()
        self.ids.layout.add_widget(Label(text=orderL))
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:
        id: "layout"
        orientation:"vertical"
        size: root.width,root.height
        padding:10
        spacing:10
        Label:
            text:"Name"
        TextInput:
            id: n
            multiline:False
        Label:
            text:"Pizza"
        TextInput:
            id: fp
            multiline:False
        Label:
            text:"Drinks"
        TextInput:
            id: d
            multiline:False
        Button:
            text:"Submit"
            on_press:root.writeD()
        Button:
            text:"Clear fields"
            on_press:root.clear()
        Button:
            text:"show orders"
            on_press:root.read()

是的,又是一个属性错误 谁能帮忙。PYTHON

【问题讨论】:

    标签: python kivy kivy-language


    【解决方案1】:

    在您的kv 文件中,ids 不应是字符串。尝试改变:

    id: "layout"
    

    到:

    id: layout
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-20
      • 1970-01-01
      • 2016-08-09
      • 1970-01-01
      相关资源
      最近更新 更多