我对python还很陌生,搜索了很多遍后都解决不了问题。也许你们能帮我。我想向1个butten添加多个命令。所以如果你有100点生命,你会失去每一次10点生命,如果你在0点你得到50点生命回来,但不知道怎么做。我已经读到你需要使用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}')
您可以将这些功能组合成一个函数:
相关问题 更多 >
编程相关推荐