Sven
Sven

Reputation: 1107

Kivy on_press method fires twice

When running the following code:


class JumpingApp(App):
    def build(self):
        game = JumpingGame()
        Clock.schedule_interval(game.update, 1.0/60.0)
        return game

class JumpingGame(ButtonBehavior, Widget):
    def update(self,dt):
        pass

    def on_press(self):
        print("1")
        print("2")

if __name__=="__main__":
    JumpingApp().run()

with the .kv file:

#:kivy 1.0.9


<JumpingGame>:
    on_press: self.on_press()

the following happens; when I click the Display the on_press() method of JumpingGame fires twice, so the output isnt't

1
2

but

1
2
1
2

How can I fix this?

Upvotes: 1

Views: 306

Answers (1)

Sven
Sven

Reputation: 1107

Found the Problem : I had to delete the line:

on_press: self.on_press()

in the .kv file because on_press is the standart name so it executed the method twice

Upvotes: 3

Related Questions