所以我试着做一个定时循环,不同的文本命令出现在屏幕上,用户必须按与文本命令对应的键。问题是因为文本是居中的,所以它只是在命令无法读取之前自动绘制。有没有一种方法可以在每次我想在窗口上绘制文本时清除窗口?我在下面发布了我当前的代码from Graphics import *
from Myro import timer #used for the animation.
import random #random starting positions and speeds
NUMBALLS = 10
WINSIZE = 500
done = 0
win = Window("GAME", WINSIZE, WINSIZE)
#win.mode = "manual" #Trick to make the animation smoother....
space = Text((180, 250), "SPACEBAR")
space.fill = Color("blue")
space.fontSize = 30
space.xJustification = "bottom"
space.yJustification = "bottom"
up = Text((180, 250), "UP")
up.fill = Color("red")
up.fontSize = 30
up.xJustification = "bottom"
up.yJustification = "bottom"
down = Text((180, 250), "DOWN")
down.fill = Color("black")
down.fontSize = 30
down.xJustification = "bottom"
down.yJustification = "bottom"
left = Text((180, 250), "LEFT")
left.fill = Color("green")
left.fontSize = 30
left.xJustification = "bottom"
left.yJustification = "bottom"
right = Text((180, 250), "RIGHT")
right.fill = Color("orange")
right.fontSize = 30
right.xJustification = "bottom"
right.yJustification = "bottom"
shape = Rectangle((0, 500), (500, 0))
shape.fill = Color("white")
keys = (space,up,left,right,down)
def handleKeyPress(win, event):
global done
if ((this == 0) and (done == 0)):
if (event.key == "space"):
print("correct")
done = 1
if ((this == 1) and (done == 0)):
if (event.key == "Up"):
print("correct")
done = 1
#if ((this == 2) and (done == 0)):
# if (event.key == "Left"):
# print("correct")
# done = 1
#if ((this == 3) and (done == 0)):
# if (event.key == "Right"):
# print("correct")
done = 1
# if ((this == 4) and (done == 0)):
# if (event.key == "Down"):
# print("correct")
# done = 1
for i in timer(5):
shape.draw(win)
this = random.randint(0,4)
me = keys[this]
me.draw(win)
onKeyPress(handleKeyPress)
print("done")
wait(0.4)
done = 0