【发布时间】:2021-07-28 20:34:18
【问题描述】:
我不知道为什么会收到此属性错误。我的代码在从用户和密码输入框中获取值时发现错误:
错误 - 文件“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"
【问题讨论】: