我怎样才能改变乌龟的颜色?
How can I change color of the turtle?
我需要多次更改龟头的颜色,就像我希望乌龟头撞到墙上时颜色闪烁多次,但是当我在屏幕上更改颜色时,只有我设置的最后一种颜色因为龟头是可见的。
def reset_score(seq):
global score
time.sleep(0.5) # the snake freezes for a moment when hitting a wall then the game resets
head.color("black")
wn.update()
head.color("yellow")
wn.update()
head.color("red")
wn.update()
head.goto(0, 0)
head.direction = "stop"
score = 0
for seq in snake_tail:
seq.goto(1000, 1000)
score = 0
score_printer.clear()
score_printer.write("Score: {} High Score: {}".format(score, high_score), align="center", font=("italic", 24, "normal"))
snake_tail.clear()
# reset the game when the head hits the wall
if head.xcor() > 290 or head.xcor() < -290 or head.ycor() > 290 or head.ycor() < -290:
reset_score("body_parts")
正如@Michael Guidry 建议的那样,您需要在每次颜色更改后添加一个小暂停,以便颜色可见。
def reset_score(seq):
global score
time.sleep(0.5) # the snake freezes for a moment when hitting a wall then the game resets
head.color("black")
wn.update()
time.sleep(0.1)
head.color("yellow")
wn.update()
time.sleep(0.1)
head.color("red")
wn.update()
time.sleep(0.1)
head.goto(0, 0)
head.direction = "stop"
score = 0
for seq in snake_tail:
seq.goto(1000, 1000)
score = 0
score_printer.clear()
score_printer.write("Score: {} High Score: {}".format(score, high_score), align="center", font=("italic", 24, "normal"))
snake_tail.clear()
# reset the game when the head hits the wall
if head.xcor() > 290 or head.xcor() < -290 or head.ycor() > 290 or head.ycor() < -290:
reset_score("body_parts")
我需要多次更改龟头的颜色,就像我希望乌龟头撞到墙上时颜色闪烁多次,但是当我在屏幕上更改颜色时,只有我设置的最后一种颜色因为龟头是可见的。
def reset_score(seq):
global score
time.sleep(0.5) # the snake freezes for a moment when hitting a wall then the game resets
head.color("black")
wn.update()
head.color("yellow")
wn.update()
head.color("red")
wn.update()
head.goto(0, 0)
head.direction = "stop"
score = 0
for seq in snake_tail:
seq.goto(1000, 1000)
score = 0
score_printer.clear()
score_printer.write("Score: {} High Score: {}".format(score, high_score), align="center", font=("italic", 24, "normal"))
snake_tail.clear()
# reset the game when the head hits the wall
if head.xcor() > 290 or head.xcor() < -290 or head.ycor() > 290 or head.ycor() < -290:
reset_score("body_parts")
正如@Michael Guidry 建议的那样,您需要在每次颜色更改后添加一个小暂停,以便颜色可见。
def reset_score(seq):
global score
time.sleep(0.5) # the snake freezes for a moment when hitting a wall then the game resets
head.color("black")
wn.update()
time.sleep(0.1)
head.color("yellow")
wn.update()
time.sleep(0.1)
head.color("red")
wn.update()
time.sleep(0.1)
head.goto(0, 0)
head.direction = "stop"
score = 0
for seq in snake_tail:
seq.goto(1000, 1000)
score = 0
score_printer.clear()
score_printer.write("Score: {} High Score: {}".format(score, high_score), align="center", font=("italic", 24, "normal"))
snake_tail.clear()
# reset the game when the head hits the wall
if head.xcor() > 290 or head.xcor() < -290 or head.ycor() > 290 or head.ycor() < -290:
reset_score("body_parts")