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

ValueError: X has 10 features, but LinearRegression is expecting 1 features as input

So, I am trying to predict the model but its throwing error like it has 10 features but it expacts only 1. So I am confused can anyone help me with it? more importantly its not working for me when my friend runs it. It works perfectly fine dose anyone know the reason about it? cv = KFold(n_splits = 10) all_loss = [] for i in range(9): # 1st for loop over polynomial orders poly_order = i X_train = make_polynomial(x, poly_order) loss_at_order = [] # initiate a set to collect loss for CV for train_index, test_index in cv.split(X_train): print('TRAIN:', train_index, 'TEST:', test_index) X_train_cv, X_test_cv = X_train[train_index], X_test[test_index] t_train_cv, t_test_cv = t[train_index], t[test_index] reg.fit(X_train_cv, t_train_cv) loss_at_order.append(np.mean((t_test_cv - reg.predict(X_test_cv))**2)) # collect loss at fold all_loss.append(np.mean(loss_at_order)) # collect loss at order plt.plot(np.log(al...

Sorting large arrays of big numeric stings

I was solving bigSorting() problem from hackerrank: Consider an array of numeric strings where each string is a positive number with anywhere from to digits. Sort the array's elements in non-decreasing, or ascending order of their integer values and return the sorted array. I know it works as follows: def bigSorting(unsorted): return sorted(unsorted, key=int) But I didnt guess this approach earlier. Initially I tried below: def bigSorting(unsorted): int_unsorted = [int(i) for i in unsorted] int_sorted = sorted(int_unsorted) return [str(i) for i in int_sorted] However, for some of the test cases, it was showing time limit exceeded. Why is it so? PS: I dont know exactly what those test cases were as hacker rank does not reveal all test cases. source https://stackoverflow.com/questions/73007397/sorting-large-arrays-of-big-numeric-stings

How to load Javascript with imported modules?

I am trying to import modules from tensorflowjs, and below is my code. test.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title </head> <body> <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@2.0.0/dist/tf.min.js"></script> <script type="module" src="./test.js"></script> </body> </html> test.js import * as tf from "./node_modules/@tensorflow/tfjs"; import {loadGraphModel} from "./node_modules/@tensorflow/tfjs-converter"; const MODEL_URL = './model.json'; const model = await loadGraphModel(MODEL_URL); const cat = document.getElementById('cat'); model.execute(tf.browser.fromPixels(cat)); Besides, I run the server using python -m http.server in my command prompt(Windows 10), and this is the error prompt in the console log of my browser: Failed to loa...