import tkinter as tk
tk = tk.Tk()
attackPhase = False
class player():
def __init__(self,master):
self.master = master
def changePhase(self,event):
global attackPhase
attackPhase = True
print(attackPhase)
def placeShip(self):
self.master.bind("<Return>",self.changePhase)
def attack(self,opponent):
print('attack phase')
player1 = player(tk)
if not attackPhase:
player1.placeShip()
else:
player1.attack(ai)
tk.mainloop()
我打算按Enter键将AttackPhase的值从False更改为True,从而运行player1.attack(ai)。
但是,按Enter键只能将False更改为True,但不会移至player1.attack(ai)
是否可以在类中的函数之间进行转换?