Skip to content Skip to sidebar Skip to footer

Python/Kivy : Call Function From One Class To Another Class And Show Widget In Python

I am using Python-2.7 and Kivy. When I run test.py then a show button shows. When I click on the show button then a label and value shows. I am fetching it from the database but no

Solution 1:

You are creating a new Invoice instance instead of using the existing one.

 Invoice().abc()

try instead:

class EditPopup(Popup):
    mode = StringProperty("")
    label_rec_id = StringProperty("Id")
    col_data = ListProperty(["?", "?", "?"])
    index = NumericProperty(0)

    def __init__(self, obj, **kwargs):
        super(EditPopup, self).__init__(**kwargs)
        self.obj = obj # will need it later...

    def update(self,obj):
        #cur.execute("UPDATE `item` SET itemName=?, itemCode=? WHERE itemId=?",
                #('Item1', 9999, 11))
        #con.commit()

        self.obj.abc()  # was Invoice().abc()

Solution 2:

Problem

You are instanting a second instance of class Invoice by invoking Invoice().abc() at method update in class EditPopup.

Solution

1) test.py

Comment off Invoice().abc() at method update in class EditPopup and add pass.

def update(self, obj):
    #cur.execute("UPDATE `item` SET itemName=?, itemCode=? WHERE itemId=?",
            #('Item1', 9999, 11))
    #con.commit()
    # Invoice().abc()
    pass

2) test.kv

Add a call to method abc in class EditPopup after call to method update.

    Button:
        size_hint_x: .5
        text: "Ok"
        on_release:
            root.update(root)
            app.root.abc()
            root.dismiss()

Output

Img01 - App Startup Img02 - Clicked Show Button Img03 - Before Changes Img04 - After Changes Img05 - After Update and invoked method abc


Post a Comment for "Python/Kivy : Call Function From One Class To Another Class And Show Widget In Python"