I'm trying to create a card in which I can place a scroll view on that appears on the viewdecks screen after the user has logged in to do this I called the ViewDecks.ShowDecks() method from inside of the login class, I think this is creating a problem as when I run the code I get this error: deck_list = self.ids.deck_scroll File "kivy\properties.pyx", line 964, in kivy.properties.ObservableDict.getattr AttributeError: 'super' object has no attribute 'getattr'.I'm not sure how to fix this.
from kivy.lang import Builder
from kivymd.app import MDApp
from kivy.uix.screenmanager import ScreenManager, Screen
import mysql.connector
from kivymd.uix.dialog import MDDialog
from kivymd.uix.button import MDRaisedButton
from kivy.uix.scrollview import ScrollView
from kivymd.uix.card import MDCard
from kivymd.uix.label import MDLabel
class Login(Screen):
def sign(self):
if self.ids.user.text == "" or self.ids.passw.text == "" or self.ids.email.text == "":
dialog = MDDialog(
text="All fields required",
buttons=[MDRaisedButton(text='OK', on_release=lambda x: dialog.dismiss())]
)
dialog.open()
else:
try:
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="root",
database="mydb"
)
mycursor = mydb.cursor()
except:
dialog = MDDialog(
text="Error, connection is not established try again later",
buttons=[MDRaisedButton(text='OK', on_release=lambda x: dialog.dismiss())]
)
dialog.open()
return
query = "SELECT * FROM users WHERE username=%s"
mycursor.execute(query, (self.ids.user.text,))
existing = mycursor.fetchone()
if existing != None:
dialog = MDDialog(
text="Username already in use",
buttons=[MDRaisedButton(text='OK', on_release=lambda x: dialog.dismiss())]
)
dialog.open()
else:
mycursor.execute("INSERT INTO users(username,pass,email) VALUES(%s,%s,%s)",
(self.ids.user.text, self.ids.passw.text, self.ids.email.text))
mydb.commit()
def log(self):
if self.ids.user.text == "" or self.ids.passw.text == "":
dialog = MDDialog(
text="Username and Password required.",
buttons=[MDRaisedButton(text='OK', on_release=lambda x: dialog.dismiss())]
)
dialog.open()
else:
try:
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="root",
database="mydb"
)
mycursor = mydb.cursor()
except:
dialog = MDDialog(
text="Error, connection is not established try again later",
buttons=[MDRaisedButton(text='OK', on_release=lambda x: dialog.dismiss())]
)
dialog.open()
return
query = "SELECT * FROM users WHERE username=%s AND pass=%s"
mycursor.execute(query, (self.ids.user.text, self.ids.passw.text))
existing = mycursor.fetchone()
if existing == None:
dialog = MDDialog(
text="Invalid username or password",
buttons=[MDRaisedButton(text='OK', on_release=lambda x: dialog.dismiss())]
)
dialog.open()
else:
self.user_id=existing[0]
self.manager.current="deck_view"
ViewDecks.ShowDecks(self)
print(self.user_id)
def clear(self):
self.ids.user.text = ""
self.ids.passw.text = ""
self.ids.email.text = ""
class ViewDecks(Screen):
def ShowDecks(self):
try:
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="root",
database="mydb"
)
mycursor = mydb.cursor()
except:
dialog = MDDialog(
text="Error, connection is not established try again later",
buttons=[MDRaisedButton(text='OK', on_release=lambda x: dialog.dismiss())]
)
dialog.open()
mycursor.execute('SELECT deck_name FROM decks WHERE user_id = %s', (self.user_id,))
decks = mycursor.fetchall()
deck_list = self.ids.deck_scroll
for deck_name in decks:
deck_card = MDCard(orientation='horizontal', size_hint=(None, None), size=(200, 300))
deck_card.add_widget(MDLabel(text=deck_name[0]))
deck_list.add_widget(deck_card)
class WindowManager(ScreenManager):
pass
class Myapp(MDApp):
def build(self):
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = 'DeepPurple'
return Builder.load_file('flashcards.kv')
Myapp().run()
kv file:
WindowManager:
Login
ViewDecks
<Login>:
MDCard:
size_hint:None, None
size:300,400
pos_hint:{"center_x":0.5, "center_y": 0.5}
padding:25
spacing:25
orientation: "vertical"
MDLabel:
id:welcome_label
text:"Welcome"
font_size:40
halign: 'center'
size_hint_y: None
height:self.texture_size[1]
padding_y:15
MDTextField:
id:user
mode:"round"
hint_text: "username"
icon_right: "account"
size_hint_x: None
width:205
font_size:18
pos_hint:{"center_x":0.5}
MDTextField:
id:passw
mode:"round"
hint_text: "password"
icon_right: "eye-off"
size_hint_x: None
width:205
font_size:18
pos_hint:{"center_x":0.5}
password:True
MDTextField:
id:email
mode:"round"
hint_text: "email(only for signup)"
icon_right: "email"
size_hint_x: None
width:205
font_size:18
pos_hint:{"center_x":0.5}
Widget:
size_hint_x:None
height:10
BoxLayout:
MDRoundFlatButton:
text: "Signup"
text_color: "white"
font_size: 15
pos_hint:{"center_x":0.2, "center_y":0.7}
size_hint_x: 0.05
on_press:root.sign()
Widget:
size_hint_x:None
width:10
MDRoundFlatButton:
text: "Login"
text_color: "white"
font_size: 15
pos_hint:{"center_x":0.7, "center_y":0.7}
size_hint_x: 0.05
on_press:root.log()
MDRoundFlatButton:
text: "Clear"
text_color: "white"
font_size: 15
pos_hint:{"center_x":0.5}
size_hint_x: 0.5
on_press: root.clear()
<ViewDecks>:
name:"deck_view"
BoxLayout:
orientation :'horizontal'
ScrollView:
BoxLayout:
orientation:'vertical'
id:deck_scroll
source https://stackoverflow.com/questions/77040054/cannot-access-id-from-method-in-kivy
Comments
Post a Comment