Retrieve Data from Firebase Database to Kivy App

98 views
Skip to first unread message

Lizzie Faye

unread,
Feb 11, 2023, 7:54:39 AM2/11/23
to Kivy users support
Hi,
I've been having some trouble accessing the path of an id that is located in a .kv file

On my main.py, I have imported the necessary libraries and also have the configurations and inistialization of firebase. I have this command that gets the data from the databse. However, I'm having trouble when passing the data/value to the id. 

Here's my code on my main.py

def get_user_data1(self, account_username):
       
        user_id = account_username
        username = database.child(user_id).child("UsersData1").child("Username").get().val()
      
        self.root.get_screen("account").ids.account_username.text = username



My account.kv file has the id account_username

MDScreen:
    name:"account"
    MDFloatLayout:
        md_bg_color: 1, 1, 1, 1        
        MDIconButton:
            icon: "chevron-left-circle"
            pos_hint: {"center_x": .1, "center_y": .945}
            user_font_size: "10sp"
            theme_text_color: "Custom"
            text_color:  rgba(11, 69, 128, 255)
            on_release:
                root.manager.transition.direction = "right"
                root.manager.current = "home"
        MDTextButton:
            text: "Back"
            font_name: "MPoppins"
            theme_text_color: "Custom"
            font_size: "18sp"
            text_color: rgba(11, 69, 128, 255)
            pos_hint: {"center_x": .23, "center_y": .946}
            on_release:
                root.manager.transition.direction = "right"
                root.manager.current = "home"

    MDFloatLayout:
        size_hint: .9, .09
        pos_hint: {"center_x": .5, "center_y": .85}
        md_bg_color: rgba(241, 241, 243, 255)
        radius: [10]
        Image:
            source: 'assets/account_small.png'
            size_hint: .5, .5
            pos_hint: {"center_x": .11, "center_y": .5}
           
        MDLabel:
            text: "> Home > Account"
            font_name: "MPoppins"
            font_size: "15sp"
            pos_hint: {"center_x": .69, "center_y": 0.5}
            color: rgba(146,146,148,255)

<AccountInfo1>:
    MDIcon:
        icon: "card-account-details"
        font_size: "18sp"
        pos_hint: {'center_x': 0.13, 'center_y': 0.77}
        theme_text_color: "Custom"
        text_color: rgba(11, 69, 128, 255)
    MDLabel:
        text: "Username"
        font_name: "MPoppins"
        font_size: "18sp"
        pos_hint: {'center_x': 0.67, 'center_y': 0.77}
        color: rgba(112, 177, 220, 255)
    MDFloatLayout:
        size_hint: .85, .09
        pos_hint: {'center_x': 0.5, 'center_y': 0.7}
        canvas:
            Color:
                rgb: rgba(241, 241, 243, 255)
            RoundedRectangle:
                size: self.size
                pos: self.pos
                radius: [10]    
        MDLabel:
            id: account_username
            #text: root.account_username_label
            #text: "Ethel"
            font_name: "MPoppins"
            font_size: "14sp"
            size_hint: 1, None
            pos_hint: {'center_x': 0.55, 'center_y': 0.5}
            theme_text_color: "Custom"
            text_color: rgba(55, 112, 148, 255)
        
Also the get_user_data1 is called when the button is released in a separate .kv file, login.kv

I've tried fixing my path to the id but i can't get it right. Also, I always get this error
 
AttributeError: 'super' object has no attribute '__getattr__'. Did you mean: '__setattr__'?

Any help would be appreciated. Thanks!


Elliot Garbus

unread,
Feb 11, 2023, 1:05:45 PM2/11/23
to kivy-...@googlegroups.com

Where are you instancing AccountInfo1 ?

 

The id you are trying to access is not in the “account” screen, it is in AccountInfo1, if you are instancing and adding AccountInfo1 with python you would need to use the children list of the account screen to get to AccountInfo1, then use the ids.

 

There are a number of techniques you could use to simplify accessing the widget – but there is not enough info here to suggest an approach.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/a11ed668-f580-4026-ba1d-255c9af50aa8n%40googlegroups.com.

 

Lizzie Faye

unread,
Feb 11, 2023, 2:09:53 PM2/11/23
to Kivy users support
Ooops, I didn't include the instance of AccountInfo1. Thanks for pointing that out! The issue is finally fixed.
Reply all
Reply to author
Forward
0 new messages