attributeerror:“super”对象在kivymd请求应用程序中没有属性“\uu getattr\uuuu”错误

bxgwgixi  于 2021-09-08  发布在  Java
关注(0)|答案(1)|浏览(349)

当我的加载文件是.kv文件时,它正在运行,但我无法打开屏幕,所以我尝试了字符串加载文件,但现在它显示了此错误。
日志有效负载={'uname':self.root.ids.user.text,'psw':self.root.ids.password.text}文件“c:\users\armof\pycharmprojects\screen\main.py”,第142行,在kivy.properties.observedict.getattr attributeerror:“super”对象没有属性“getattr”
感谢您的努力:)

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()
0pizxfdo

0pizxfdo1#

问题是 self.root.ids 是空字典,因此尝试访问该空字典中的任何键将导致该错误。这个 ids 您正在尝试访问的文件位于 MenuScreen 示例,您可以使用 get_screen() 方法 ScreenManager ,例如:

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

代码中的其他地方也有相同的错误。无论你在哪里 self.root.ids ,则需要应用类似的逻辑。

相关问题