简体   繁体   English

'super' object 没有属性 '__getattr__',谁能帮帮我?

[英]'super' object has no attribute '__getattr__', can anyone help me?

imports:进口:

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.textinput import TextInput
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.properties import StringProperty
from kivy.properties import ObjectProperty
from kivy.uix.label import Label
from kivy.core.window import Window
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.boxlayout import BoxLayout
kv = '''

<Login>
    ben: benName.text
    pw: passwort.text
    knopf: btn
    knopff: btnn
 
    GridLayout:
        cols: 1
        size: root.width,root.height
        GridLayout:
            cols: 2
            Label:
                text: "Username"
                font_size: 25
            TextInput:
                id: benName
                multiline: False
                font_size: 30
            Label:
                text: "Password"
                font_size: 25
                bold: True
            TextInput:
                password: True
                id: passwort
                multiline: False
                font_size: 40
        Button:
            size_hint: (1.,1.10)
            text:" Start "
            id: btn
            font_size: 40
            on_release:
                root.manager.current = "Readed" if passwort.text == "1" and benName.text == "1" else "login"
                root.manager.transition.direction = "down"
        Button:
            size_hint: (1.,1.10)
            text: " Exit "
            id: btnn
            font_size: 40
            on_release: app.stop()






<readed>:
    BoxLayout:
        orientation: 'vertical'
        TextInput:
            id: text_field
        Button:
            text: 'click'
            on_press: app.read()

'''

MyApp class:我的应用程序MyApp

class Login(Screen):
    ben = StringProperty()
    pw = StringProperty()
    knopf = ObjectProperty()


class MyApp(App):
    Builder.load_string(kv)
    def read(self):
        file = open("read.txt", 'r')
        f = file.readlines()
        self.root.ids.text_field.text = (''.join(f))
        text = StringProperty("read.txt")
    def build(self):
        ms = ScreenManager()
        ms.add_widget(Login(name='login'))
        ms.add_widget(Readed(name='Readed'))
        self.title = "MyApp"
        return ms





class Readed(Screen):
    pass




if __name__ == '__main__':
    MyApp().run()
# her is the erorr
 #exec(__kvlang__.co_value, idmap)
   #File "<string>", line 59, in <module>
   #File "C:\Users\---\--\Desktop\B-PYTHON\----\TEST 45.py", line 93, in read
     #self.root.ids.text_field.text = (''.join(f))
   #File "kivy\properties.pyx", line 864, in kivy.properties.ObservableDict.__getattr__
 #AttributeError: 'super' object has no attribute '__getattr__'
#[Finished in 5.9s with exit code 1]

The line of code:代码行:

self.root.ids.text_field.text = (''.join(f))

is trying to access the ids of the app root.正在尝试访问应用程序根目录的ids But the app root is the ScreenManager , which has no ids (because it does not appear in the kv ).但是应用根目录是ScreenManager ,它没有ids (因为它没有出现在kv中)。 That is what causes the error.这就是导致错误的原因。

The fix is to access the ids of the Readed Screen , because that is where the text_field is defined.解决方法是访问Readed Screenids ,因为这是定义text_field的地方。 Try something like:尝试类似:

self.root.get_screen('Readed').ids.text_field = (''.join(f))

Since root is the ScreenManager , you can use get_screen() to get a reference to the Readed Screen .由于rootScreenManager ,您可以使用get_screen()来获取对Readed Screen的引用。 Once you have that reference, you can use the ids defined in the Screen by the kv .获得该参考后,您可以使用kvScreen中定义的ids

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AttributeError:“超级”对象没有属性“ __getattr__” - AttributeError: 'super' object has no attribute '__getattr__' 'super' object 在 kivymd 中没有属性 '__getattr__' - 'super' object has no attribute '__getattr__' in kivymd AttributeError:“超级”对象没有属性“ __getattr __”(我进行了搜索,但无济于事) - AttributeError: 'super' object has no attribute '__getattr__' ( I searched, but to no avail) &#39;super&#39;对象在python3中没有属性&#39;__getattr__&#39; - 'super' object has no attribute '__getattr__' in python3 AttributeError: &#39;super&#39; 对象在 python 中没有属性 &#39;__getattr__&#39; - AttributeError: 'super' object has no attribute '__getattr__' in python Kivy: AttributeError: 'super' object 没有属性 '__getattr__' - Kivy: AttributeError: 'super' object has no attribute '__getattr__' Kivy AttributeError: 'super' object 没有属性 '__getattr__' - Kivy AttributeError: 'super' object has no attribute '__getattr__' Kivy AttributeError: 'super' object has no attribute '__getattr__' 错误 - Kivy AttributeError: 'super' object has no attribute '__getattr__' error Python Kivy 返回 'AttributeError: 'super' object 没有属性 '__getattr__'' - Python Kivy returning 'AttributeError: 'super' object has no attribute '__getattr__'' 屏幕管理器(AttributeError:“ super”对象没有属性“ __getattr__”) - screen manager (AttributeError: 'super' object has no attribute '__getattr__')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM