为了账号安全,请及时绑定邮箱和手机立即绑定

Python 多命令 tkinter

Python 多命令 tkinter

狐的传说 2021-09-11 10:46:11
我对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 回答

?
慕尼黑5688855

TA贡献1848条经验 获得超2个赞

您可以将这些组合成一个函数就好了:

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


查看完整回答
反对 回复 2021-09-11
  • 1 回答
  • 0 关注
  • 150 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信