简体   繁体   English

AttributeError: 'super' 对象在 kivymd 请求应用程序中没有属性 '__getattr__' 错误

[英]AttributeError: 'super' object has no attribute '__getattr__' error at kivymd request app

it was running while my load file was .kv file but I cant switch screen on condition so I tried string load file but now It show this error.它正在运行,而我的加载文件是 .kv 文件,但我无法在条件下切换屏幕,所以我尝试了字符串加载文件,但现在它显示了这个错误。

File "C:\\Users\\armof\\PycharmProjects\\screen\\main.py", line 142, in logger payload={'Uname': self.root.ids.user.text, 'psw': self.root.ids.password.text} File "kivy\\properties.pyx", line 864, in kivy.properties.ObservableDict.文件“C:\\Users\\armof\\PycharmProjects\\screen\\main.py”,第 142 行,记录器 payload={'Uname': self.root.ids.user.text, 'psw': self.root.ids。 password.text} 文件“kivy\\properties.pyx”,第 864 行,在 kivy.properties.ObservableDict 中。 getattr AttributeError: 'super' object has no attribute ' getattr ' getattr AttributeError: 'super' 对象没有属性 ' getattr '

Thanks for your efforts :)感谢您的努力:)

from kivymd.app import MDApp
from kivy.lang.builder import Builder
from kivy.uix.screenmanager import Screen,ScreenManager
import requests

screen_helper = """
ScreenManager:
    MenuScreen:
    ProfileScreen:
    
<MenuScreen>:
    name : "login"
    Image:
        source:"C:/arka.png"


    MDCard:
        size_hint:None,None
        size: 400,600
        pos_hint : {"center_x":0.5,"center_y":0.5}
        elevation:10
        padding:25
        spacing:25
        orientation : 'vertical'
        Image:
            source:"C:/burbantgrilogo.png"
            pos:300,380





        MDLabel:

            text:""
            id:welcome_label
            font_size:30
            halign : 'center'
            size_hint_y:None
            height:self.texture_size[1]
            padding_y:15




        MDTextFieldRound:
            id: user
            hint_text:"username"
            icon_right:"account"
            size_hint_x:None
            width: 200
            font_size:18
            pos_hint:{"center_x":0.5}

        MDTextFieldRound:
            id: password
            hint_text:"password"
            icon_right:"eye-off"
            size_hint_x:None
            width: 200
            font_size:18
            pos_hint:{"center_x":0.5}
            password:True

        MDRoundFlatButton:
            text:"LOG IN"
            font_size: 12
            pos_hint:{"center_x":0.5}
            on_press:app.logger()





        MDRoundFlatButton:
            text:"CLEAR"
            font_size: 12
            pos_hint:{"center_x":0.5}
            on_press:app.clear()

        Widget:
            size_hint_y: None
            height: 70
                
<ProfileScreen>:
    name:"Teklif"
    Image:
        source:"C:/arka.png"

    MDCard:
        size_hint:None,None
        size: 400,600
        pos_hint : {"center_x":0.5,"center_y":0.5}
        elevation:10
        padding:25
        spacing:25
        orientation : 'vertical'

        Image:
            source:"C:/burbantgrilogo.png"
            pos:300,380




        MDRoundFlatButton:
            text:"OPEN"
            font_size: 12
            pos_hint:{"center_x":0.5}

            on_release: root.current = "login"

        MDRoundFlatButton:
            text:"NEW"
            font_size: 12
            pos_hint:{"center_x":0.5}
        Widget:
            size_hint_y: None
            height: 130
            
"""
class MenuScreen(Screen):
    pass

class ProfileScreen(Screen):
    pass

sm = ScreenManager()
sm.add_widget(MenuScreen(name='login'))
sm.add_widget(ProfileScreen(name='Teklif'))

class MainApp(MDApp):
    def build(self):
        self.theme_cls.theme_style = "Light"
        self.theme_cls.primary_palette = "Red"
        screen = Builder.load_string(screen_helper)
        return screen

    def logger(self, *args):


        payload={'Uname': self.root.ids.user.text, 'psw': self.root.ids.password.text}
        print(payload)
        r = requests.get(f"http://burbant.com/otomasyon?Uname={self.root.ids.user.text}&psw={self.root.ids.password.text}")
        print(r.text)

        if r.text == 'True':

            self.root.ids.welcome_label.text = f'Hoşgeldin {self.root.ids.user.text}!'
            sm.switch_to(screen='Teklif')




        else:
            self.root.ids.welcome_label.text = f'Hatalı'
    def clear(self):
        self.root.ids.welcome_label.text = ""
        self.root.ids.user.text = ""
        self.root.ids.password.text = ""


MainApp().run()

The problem is that self.root.ids is an empty dictionary, so trying to access any key in that empty dictionary will cause that error.问题在于self.root.ids是一个空字典,因此尝试访问该空字典中的任何键都会导致该错误。 The ids that you are trying to access are in the MenuScreen instance, which you can access using the get_screen() method of ScreenManager , like this:您尝试访问的ids位于MenuScreen实例中,您可以使用ScreenManagerget_screen()方法访问该get_screen() ,如下所示:

def logger(self, *args):
    menuscreen = self.root.get_screen('login')
    payload = {'Uname': menuscreen.ids.user.text, 'psw': menuscreen.ids.password.text}
    print(payload)
    .
    .
    .

You have the same error elsewhere in your code.您的代码中的其他地方也有同样的错误。 Wherever you have self.root.ids , you will need to apply similar logic.无论您在哪里拥有self.root.ids ,您都需要应用类似的逻辑。

暂无
暂无

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

相关问题 kivymd: AttributeError: 'super' object 没有属性 '__getattr__' - kivymd: 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__' Kivy AttributeError: 'super' object has no attribute '__getattr__' 错误 - Kivy AttributeError: 'super' object has no attribute '__getattr__' error KIVY 错误:AttributeError:&#39;super&#39; 对象没有属性 &#39;__getattr__&#39; - KIVY ERROR: AttributeError: 'super' object has no attribute '__getattr__' AttributeError:“超级”对象没有属性“ __getattr __”(我进行了搜索,但无济于事) - AttributeError: 'super' object has no attribute '__getattr__' ( I searched, but to no avail) 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__' Python Kivy 返回 'AttributeError: 'super' object 没有属性 '__getattr__'' - Python Kivy returning 'AttributeError: 'super' object has no attribute '__getattr__''
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM