Skip to main content

Cannot access ID from method in kivy

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

Popular posts from this blog

Confusion between commands.Bot and discord.Client | Which one should I use?

Whenever you look at YouTube tutorials or code from this website there is a real variation. Some developers use client = discord.Client(intents=intents) while the others use bot = commands.Bot(command_prefix="something", intents=intents) . Now I know slightly about the difference but I get errors from different places from my code when I use either of them and its confusing. Especially since there has a few changes over the years in discord.py it is hard to find the real difference. I tried sticking to discord.Client then I found that there are more features in commands.Bot . Then I found errors when using commands.Bot . An example of this is: When I try to use commands.Bot client = commands.Bot(command_prefix=">",intents=intents) async def load(): for filename in os.listdir("./Cogs"): if filename.endswith(".py"): client.load_extension(f"Cogs.{filename[:-3]}") The above doesnt giveany response from my Cogs ...

How to show number of registered users in Laravel based on usertype?

i'm trying to display data from the database in the admin dashboard i used this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count(); echo $users; ?> and i have successfully get the correct data from the database but what if i want to display a specific data for example in this user table there is "usertype" that specify if the user is normal user or admin i want to user the same code above but to display a specific usertype i tried this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count()->WHERE usertype =admin; echo $users; ?> but it didn't work, what am i doing wrong? source https://stackoverflow.com/questions/68199726/how-to-show-number-of-registered-users-in-laravel-based-on-usertype

Where and how is this Laravel kernel constructor called? [closed]

Where and how is this Laravel kernel constructor called? public fucntion __construct(Application $app, $Router $roouter) { } I have read the documentation and some online tutorial but I can find any clear explanation. I am learning Laravel and I am wondering where does this kernel constructor receives its arguments from. "POSTMOTERM" CLARIFICATION: Here is more clarity.I have checked the boostrap/app.php and it is only used for boostrapping the interfaces into the container class. What is not clear to me is where and how the Kernel class is instatiated and the arguments passed to the object calling the constructor.Something similar to; obj = new kernel(arg1,arg2) or, is the framework using some magic functions somewhere? Special gratitude to those who burn their eyeballs and brain cells on this trivia before it goes into a full blown menopause alias "MARKED AS DUPLICATE". To some of the itchy-finger keyboard warriors, a.k.a The mods,because I believe in th...