我正在尝试用Python海龟图形制作一个connect4游戏,它进行得很顺利,但后来发生了这样的事情:xy
根本不会改变!代码如下:
import turtle
from turtle import *
from turtle import Turtle, Screen
speed(0)
xy = 1
def circle1 ():
forward(90)
fillcolor("white")
begin_fill()
circle(40)
end_fill()
def getCoords(x,y):
global xy
#print("( " + str(x) + ", " + str(y) + " )")
if y < 252 and x < -316:
print ("test")
xy = 1
elif y < 252 and x > -316 and x < -187:
xy = 2
elif y < 252 and x > -187 and x < -59:
xy = 3
elif y < 252 and x > -59 and x < 65:
xy = 4
elif y < 252 and x > 65 and x < 194:
xy = 5
elif y < 252 and x > 194 and x < 327:
xy = 6
elif y < 252 and x > 327 and x < 453:
xy = 7
window = Screen()
wn = window
wn.screensize()
wn.setup(width = 1.0, height = 1.0)
begin_fill()
width(5)
penup()
goto(-450,250)
right(90)
pendown()
forward(580)
left(90)
forward(450*2)
left(90)
forward(580)
left(90)
forward(450*2)
end_fill()
right(180)
forward(30)
right(90)
forward(50)
fillcolor("white")
begin_fill()
circle(40)
end_fill()
circle1 ()
circle1 ()
circle1 ()
circle1 ()
circle1 ()
goto(-450,250)
left(90)
forward(160)
right(90)
forward(50)
fillcolor("white")
begin_fill()
circle(40)
end_fill()
circle1 ()
circle1 ()
circle1 ()
circle1 ()
circle1 ()
penup()
goto(-450,250)
pendown()
left(90)
forward(290)
right(90)
forward(50)
fillcolor("white")
begin_fill()
circle(40)
end_fill()
circle1 ()
circle1 ()
circle1 ()
circle1 ()
circle1 ()
penup()
goto(-450,250)
pendown()
left(90)
forward(410)
right(90)
forward(50)
fillcolor("white")
begin_fill()
circle(40)
end_fill()
circle1 ()
circle1 ()
circle1 ()
circle1 ()
circle1 ()
penup()
goto(-450,250)
pendown()
left(90)
forward(540)
right(90)
forward(50)
fillcolor("white")
begin_fill()
circle(40)
end_fill()
circle1 ()
circle1 ()
circle1 ()
circle1 ()
circle1 ()
penup()
goto(-450,250)
pendown()
left(90)
forward(670)
right(90)
forward(50)
fillcolor("white")
begin_fill()
circle(40)
end_fill()
circle1 ()
circle1 ()
circle1 ()
circle1 ()
circle1 ()
penup()
goto(-450,250)
pendown()
left(90)
forward(800)
right(90)
forward(50)
fillcolor("white")
begin_fill()
circle(40)
end_fill()
circle1 ()
circle1 ()
circle1 ()
circle1 ()
circle1 ()
turtle.onscreenclick(getCoords)
turtle.listen()
if xy == 1:
textinput("test","dis is 1")
出于某种奇怪的原因,当我将所有内容都添加到标签上时,复制了其中的一部分,所以忽略最后一点。你知道吗
你知道当你以三种不同的方式导入同一个模块时,事情并不是很顺利:
它正在改变,但是在你的代码中没有任何东西能够显示改变。查看
xy
的唯一语句:在
xy
更改之前完成,并且不再运行。让我们添加一些代码来在turtle窗口中显示xy
,这样您就可以看到您的点击正在产生效果。我们会清理你的代码:相关问题 更多 >
编程相关推荐