【发布时间】:2017-05-13 07:12:20
【问题描述】:
我正在制作井字游戏,我已经在寻找如何使用 Python Turtle 的 onclick() 获得 2 个位置。我得到的东西就在这个链接上: Python 3.0 using turtle.onclick。 我想获得 2 个职位,但“turtle.mainloop()”有问题 我的解决方案是:
def getPosX(x_X, y_X):
print("(", x_X, ",", y_X,")")
def getPosO(x_O, y_O):
print("(", x_O, ",", y_O,")"
def choiceX():
Xplay = turtle.getscreen()
Xplay.onclick(getPosX)
turtle.mainloop()
return Xplay
def choiceO():
Oplay = turtle.getscreen()
Oplay.onclick(getPosO)
turtle.mainloop()
return Oplay
我得到的只是 Xplay.onclick() 的位置。
我还尝试删除每个 def 的“turtle.mainloop()”,以便在另一个 def 中使用 for 循环:
def play():
for i in range(3):
choiceX()
choiceO()
return i
它不起作用。 我想我需要更好的衡量标准 谢谢
【问题讨论】: