Hello while using kivy i encountered this error. My purpose is to create a login screen of my app which will check whether the data entered by user is correct or not. But while doing so i am getting this error again and again.
My code is given below:
Python file:
from kivy.lang import Builder
from kivymd.app import MDApp
import mysql.connector as ms
from kivy.properties import StringProperty, NumericProperty
from kivy.uix.screenmanager import ScreenManager, Screen
acc = NumericProperty("")
pw = StringProperty("")
class safarApp(MDApp):
def build(self):
self.theme_cls.theme_style = 'Dark'
self.theme_cls.primary_palette = 'BlueGray'
return
def Login(self):
self.acc = self.root.ids.acc_num.text
self.pw = self.root.ids.password.text
host = ms.connect(
host="localhost",
user="root",
password="bhawarth20",
database="safar"
)
cur = host.cursor(buffered = True)
cur.execute("Select * from data where Account_Number = %s and Password = %s collate utf8mb4_bin", (self.acc, self.pw))
data="error" #initially just assign the value
for i in cur:
data=i #if cursor has no data then loop will not run and value of data will be 'error'
if data== "error":
print("User Does not exist")
else:
print("User exist")
class LoginScreen(Screen):
pass
class SignUpScreen(Screen):
pass
sm = ScreenManager()
sm.add_widget(LoginScreen(name= "login"))
sm.add_widget(SignUpScreen(name= "signup"))
if __name__ == '__main__':
safarApp().run()
KV file:
ScreenManager:
LoginScreen:
SignUpScreen:
<LoginScreen>:
name: 'login'
MDCard:
size_hint: None, None
size: 300,400
pos_hint: {'center_x': .5, 'center_y': .5}
elevation:10
spacing: 25
padding: 25
orientation: 'vertical'
MDLabel:
text: "Safar Login"
font_size: 40
halign: 'center'
size_hint_y: None
height: self.texture_size[1]
padding_y: 10
pos_hint: {'center_y': 1}
MDTextField:
id: acc_num
hint_text: 'Account Number'
icon_right: 'account'
max_text_length: 6
size_hint_x: None
pos_hint: {'center_x': .5}
width: 200
font_size: 18
required: True
MDTextField:
id: password
hint_text: 'Password'
password: True
size_hint_x: None
pos_hint: {'center_x': .5}
width: 200
font_size: 18
icon_right: 'eye'
required: True
MDFillRoundFlatButton:
id: Login
text: 'Login'
size_hint_x: None
pos_hint: {'center_x': .5}
width: 200
elevation: 10
on_release: app.Login()
MDFillRoundFlatButton:
id: Sign_Up
text: 'Sign Up'
size_hint_x: None
pos_hint: {'center_x': .5}
width: 200
elevation: 10
on_release: root.manager.current = 'signup'
<SignUpScreen>:
name: 'signup'
MDLabel:
text: "Hello World!!!"
This is the error i am getting:
[INFO ] [Logger ] Record log in C:\Users\Welcome\.kivy\logs\kivy_21-07-12_51.txt
[INFO ] [deps ] Successfully imported "kivy_deps.angle" 0.3.0
[INFO ] [deps ] Successfully imported "kivy_deps.glew" 0.3.0
[INFO ] [deps ] Successfully imported "kivy_deps.sdl2" 0.3.1
[INFO ] [Kivy ] v2.0.0
[INFO ] [Kivy ] Installed at "C:\Users\Welcome\AppData\Local\Programs\Python\Python38-32\lib\site-packages\kivy\__init
py"
[INFO ] [Python ] v3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 22:45:29) [MSC v.1916 32 bit (Intel)]
[INFO ] [Python ] Interpreter at "C:\Users\Welcome\AppData\Local\Programs\Python\Python38-32\python.exe"
[INFO ] [Factory ] 186 symbols loaded
[INFO ] [KivyMD ] 0.104.2, git-bc7d1f5, 2021-06-06 (installed at "C:\Users\Welcome\AppData\Local\Programs\Python\Python3
2\lib\site-packages\kivymd\__init__.py")
[INFO ] [Image ] Providers: img_tex, img_dds, img_sdl2, img_pil (img_ffpyplayer ignored)
[INFO ] [Text ] Provider: sdl2
[INFO ] [Window ] Provider: sdl2
[INFO ] [Window ] Activate GLES2/ANGLE context
[INFO ] [GL ] Using the "OpenGL" graphics system
[INFO ] [GL ] Backend used <angle_sdl2>
[INFO ] [GL ] OpenGL version <b'OpenGL ES 2.0.0 (ANGLE 2.1.13739 git hash: 385fb40fd460)'>
[INFO ] [GL ] OpenGL vendor <b'Google Inc.'>
[INFO ] [GL ] OpenGL renderer <b'ANGLE (Mobile Intel(R) 965 Express Chipset Family Direct3D11 vs_4_0 ps_4_0)'>
[INFO ] [GL ] OpenGL parsed version: 2, 0
[INFO ] [GL ] Shading version <b'OpenGL ES GLSL ES 1.00 (ANGLE 2.1.13739 git hash: 385fb40fd460)'>
[INFO ] [GL ] Texture max size <8192>
[INFO ] [GL ] Texture max units <16>
[INFO ] [Window ] auto add sdl2 input provider
[INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
[INFO ] [GL ] NPOT texture support is available
[INFO ] [Base ] Start application main loop
[INFO ] [Base ] Leaving application in progress...
Traceback (most recent call last):
File "kivy\properties.pyx", line 861, in kivy.properties.ObservableDict.__getattr__
KeyError: 'acc_num'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\my projects of python\Safar\safar.py", line 69, in <module>
safarApp().run()
File "C:\Users\Welcome\AppData\Local\Programs\Python\Python38-32\lib\site-packages\kivy\app.py", line 950, in run
runTouchApp()
File "C:\Users\Welcome\AppData\Local\Programs\Python\Python38-32\lib\site-packages\kivy\base.py", line 582, in runTouchApp
EventLoop.mainloop()
File "C:\Users\Welcome\AppData\Local\Programs\Python\Python38-32\lib\site-packages\kivy\base.py", line 347, in mainloop
self.idle()
File "C:\Users\Welcome\AppData\Local\Programs\Python\Python38-32\lib\site-packages\kivy\base.py", line 391, in idle
self.dispatch_input()
File "C:\Users\Welcome\AppData\Local\Programs\Python\Python38-32\lib\site-packages\kivy\base.py", line 342, in dispatch_inpu
post_dispatch_input(*pop(0))
File "C:\Users\Welcome\AppData\Local\Programs\Python\Python38-32\lib\site-packages\kivy\base.py", line 308, in post_dispatch
put
wid.dispatch('on_touch_up', me)
File "kivy\_event.pyx", line 709, in kivy._event.EventDispatcher.dispatch
File "C:\Users\Welcome\AppData\Local\Programs\Python\Python38-32\lib\site-packages\kivymd\uix\behaviors\ripple_behavior.py",
ne 296, in on_touch_up
return super().on_touch_up(touch)
File "C:\Users\Welcome\AppData\Local\Programs\Python\Python38-32\lib\site-packages\kivymd\uix\button.py", line 981, in on_to
_up
return super().on_touch_up(touch)
File "C:\Users\Welcome\AppData\Local\Programs\Python\Python38-32\lib\site-packages\kivy\uix\behaviors\button.py", line 179,
on_touch_up
self.dispatch('on_release')
File "kivy\_event.pyx", line 705, in kivy._event.EventDispatcher.dispatch
File "kivy\_event.pyx", line 1248, in kivy._event.EventObservers.dispatch
File "kivy\_event.pyx", line 1132, in kivy._event.EventObservers._dispatch
File "C:\Users\Welcome\AppData\Local\Programs\Python\Python38-32\lib\site-packages\kivy\lang\builder.py", line 57, in custom
llback
exec(__kvlang__.co_value, idmap)
File "D:\my projects of python\Safar\safar.kv", line 56, in <module>
on_release: app.Login()
File "D:\my projects of python\Safar\safar.py", line 27, in Login
self.acc = self.root.ids.acc_num.text
File "kivy\properties.pyx", line 864, in kivy.properties.ObservableDict.__getattr__
AttributeError: 'super' object has no attribute '__getattr__'
Please help me to get this error solved soon. Any help would be greatly aprreciated.
Your code:
self.acc = self.root.ids.acc_num.text
self.pw = self.root.ids.password.text
is trying to access ids
that are not in the root
ids
dictionary. Those ids
are defined in the <LoginScreen>:
rule, so they appear in the LoginScreen
instance. Replace those two line with:
login_screen = self.root.get_screen('login')
self.acc = login_screen.ids.acc_num.text
self.pw = login_screen.ids.password.text