首页 文章

Python多命令tkinter

提问于
浏览
0

我是python的新手,在搜索了很多之后无法解决问题 . 也许你们可以帮助我 . 我想在1个butten中添加多个命令 . 因此,如果你有100hp,你每次10hp都会失败,如果你在0hp你会得到50hp,但不知道该怎么做 . 我已经读过你需要使用1个函数并在两个函数内部但是当我这样做时我得到一个错误 .

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}')

1 回答

  • 1

    您可以将这些功能组合成一个功能:

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

相关问题