Number70
Number70

Reputation: 453

Python multiple commands tkinter

Im quite new to python and cant solve a problem after searching a lot. Maybe you guys can help me out. I want to add multiple commands to 1 butten. So if you have 100hp, you will lose every time 10hp and if you are on 0hp you get 50hp back, but dont know how to do that. I have read you need to use 1 function and inside both functions but when im doing that i get an error.

player_1_lose_10_Button = Button(self, text = "10 HP", command=self.myfunction)
    player_1_lose_10_Button.place(x=180,y=140)

def myfunction(self):
     lose10(self)
     check(self)

def check(self):
    global player1health
    if player1health <= 0:
        player1health +=50
        player_1_lose_10_Button = Button(self, text = "50 HP", command=self.check)        
        print('You died, you get 50hp back')

def lose10(self):
    global player1health
    player1health-=10
    print(f'You lost 10 HP, current HP: {player1health}')

Upvotes: 0

Views: 46

Answers (1)

Hack Saw
Hack Saw

Reputation: 2781

You can combine these into one function just fine:

def lose_but_check(self):
    self.lose10()
    self.check()

Upvotes: 1

Related Questions