我對(duì)python很陌生,經(jīng)過大量搜索后無法解決問題。或許你們可以幫幫我。我想向 1 個(gè)butten 添加多個(gè)命令。所以如果你有 100hp,你每次都會(huì)輸 10hp,如果你是 0hp,你會(huì)得到 50hp,但不知道怎么做。我讀過你需要使用 1 個(gè)函數(shù)并且在這兩個(gè)函數(shù)中,但是當(dāng)我這樣做時(shí),我得到一個(gè)錯(cuò)誤。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 回答

慕尼黑5688855
TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超2個(gè)贊
您可以將這些組合成一個(gè)函數(shù)就好了:
def lose_but_check(self): self.lose10() self.check()
添加回答
舉報(bào)
0/150
提交
取消