简体   繁体   中英

I am getting an attribute error ( AttributeError: 'super' object has no attribute '__getattr__') while running my script

I don't know why I am getting this attribute error. My code finds an error in getting the values from the user and password entry boxes:

Error- File "d:\\Desktop\\kivymd\\login.py", line 36, in verify user = self.root.ids.user.text File "kivy\\properties.pyx", line 864, in kivy.properties.ObservableDict.__getattr__ AttributeError: 'super' object has no attribute '__getattr__'

from kivy.config import Config
from kivy import Config
Config.set('graphics', 'width', '400')
Config.set('graphics', 'height', '500')
Config.set('graphics', 'resizable', 'False')
from kivy.lang import Builder
from kivymd.app import MDApp
from kivy.uix.screenmanager import ScreenManager, Screen
import sqlite3


class MainWindow(Screen):
    pass


class SecondWindow(Screen):
    pass


class WindowManager(ScreenManager):
    pass

class MainApp(MDApp):
   
    def build(self):
      
       Config.set('graphics', 'resizable', False)
       self.theme_cls.theme_style = "Dark"
       self.theme_cls.primary_palette = "Purple"
       return Builder.load_file("login.kv")            
    def verify(self):            
        conn = sqlite3.connect("master.db")
        cur = conn.cursor()
        
        
        user = self.root.ids.user.text
        password = self.root.ids.password.text
        print(user)
        print(password)
        if user=="" or password=="" :  
           self.root.ids.error.markup=True
           self.root.ids.error.text = "[b][color=#f50539]materuser & masterpassword required ![/b][/color]" 
           
        else:           
            cur.execute("SELECT rowid , *FROM master_database WHERE master_users = ?", (user,))
            
            c=cur.fetchone()
            conn.commit()
            conn.close()
        
            if c==None:
                self.root.ids.error.markup=True
                
                self.root.ids.error.text = f"No data for [color=#f50539][b]{user}[/b][/color]\nKindly register for [color=#f50539][b]new user ![/b][/color]" 
               
                                                    
            else:
                    
                    if c[2] == password:
                        self.root.ids.error.markup=True
                        self.root.ids.error.text = "[b]Successfully verified.Click to Login[b]"
                       # self.root.ids.log_in.on_release.app.root.current = "second"
                        
                        
                    else:
                        self.root.ids.error.markup=True
                        self.root.ids.error.text = "[b]Incorrect Password ![b]"   
MainApp().run() 



  

My .kv file ----->

WindowManager:
    MainWindow:
    SecondWindow:

<MainWindow>:
    name: "main"

    MDCard:
        size_hint:None,None
        size:400,500
        pos_hint:{"center_x":.5,"center_y":.5}
        elevation:10
        padding:25
        spacing:25

        orientation:"vertical"

        MDLabel:
            markup:True
            id:welcome_label
            text:"[b]PASSWORD MANAGER[/b]"
            font_size:40
            halign: "center"
            size_hint_y:  None
            height:self.texture_size[1]
            padding_y:-10  

        MDTextFieldRound:
            id:user
            hint_text: "master usename"
            icon_right: "account"
            size_hint_x: None
            width:200
            font_size:18
            pos_hint:{"center_x":0.5}
        MDTextFieldRound:
            id:password
            hint_text: "master password"
            icon_right: "eye_off"
            size_hint_x: None
            width:200
            font_size:18
            pos_hint:{"center_x":0.5}
            password:True

        MDRoundFlatButton:
            id : verify
            text:"VERIFY"   
            font_size:12
            pos_hint:{"center_x":.5}
            on_press: app.verify()
                
<SecondWindow>:
    name: "second"
    Button:
        text: "Go Back"
        on_release:
            app.root.current = "main"
            root.manager.transition.direction = "right"

You are trying to access ids from an object that has no ids . The user and password ids will be in the ids of the MainWindow . So whenever you have code that tries accesses those ids , like:

    user = self.root.ids.user.text
    password = self.root.ids.password.text

You should modify that code to access the ids of MainWindow :

    user = self.root.get_screen('main').ids.user.text
    password = self.root.get_screen('main').ids.password.text

The above code calls the get_screen() method of ScreenManager (which is self.root ) to access the MainWindow . Then you can access the ids of that object.

Note that the ids defined in the kv only appear in the object that is the root of the current rule. And all your ids are defined in the <MainWindow> rule.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM