亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Python 多命令 tkinter

Python 多命令 tkinter

狐的傳說 2021-09-11 10:46:11
我對python很陌生,經過大量搜索后無法解決問題?;蛟S你們可以幫幫我。我想向 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 回答

?
慕尼黑5688855

TA貢獻1848條經驗 獲得超2個贊

您可以將這些組合成一個函數就好了:

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


查看完整回答
反對 回復 2021-09-11
  • 1 回答
  • 0 關注
  • 188 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號