我对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}')
慕尼黑5688855
相关分类