L Lochana
L Lochana

Reputation: 79

How to call a function when clicked a kivy button?

I'm pretty new to kivy. I want to call a function in the App class. But it gives an error. The error is "on_press: app.hello() TypeError: hello() takes 0 positional arguments but 1 was given"

.kv file code

            Button:
            id: add_income_btn
            size_hint: (.05, .2)
            pos: (393, 302)
            background_color: (1, 1, 1, 0)
            text: "+"
            font_size:'20sp'
            on_press: app.hello()

.py file code

Builder.load_file("test1.kv")
class Money_Manager(App,TabbedPanel): 
    def hello():
        print("Hello")

Upvotes: 0

Views: 68

Answers (2)

noEmbryo
noEmbryo

Reputation: 2231

The methods of an instantiated Class in Python need a self argument (the current Class instance).
So you must use:

    def hello(self):
        print("Hello")

Upvotes: 1

Mr_Zed
Mr_Zed

Reputation: 3

Try This One :

on_press: app.hello

instead of

on_press: app.hello()

Upvotes: 0

Related Questions