[英]I am not sure why but I am getting error: “AttributeError: 'super' object has no attribute '__getattr__'”
[英]I am getting an attribute error ( AttributeError: 'super' object has no attribute '__getattr__') while running my script
我不知道为什么我会收到此属性错误。 我的代码在从用户和密码输入框中获取值时发现错误:
错误 - 文件“d:\\Desktop\\kivymd\\login.py”,第 36 行,在验证用户 = self.root.ids.user.text 文件“kivy\\properties.pyx”,第 864 行,在 kivy.properties.ObservableDict .__getattr__ AttributeError: 'super' 对象没有属性 '__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()
我的 .kv 文件 ----->
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"
您正在试图访问ids
从没有一个对象ids
。 user
和password
ids
将在MainWindow
的ids
中。 因此,只要您有尝试访问这些ids
代码,例如:
user = self.root.ids.user.text
password = self.root.ids.password.text
您应该修改该代码以访问MainWindow
的ids
:
user = self.root.get_screen('main').ids.user.text
password = self.root.get_screen('main').ids.password.text
上面的代码调用了ScreenManager
(即self.root
)的get_screen()
方法来访问MainWindow
。 然后您可以访问该对象的ids
。
请注意, kv
定义的ids
仅出现在作为当前规则根的对象中。 您的所有ids
都在<MainWindow>
规则中定义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.