【发布时间】:2015-02-26 02:19:24
【问题描述】:
所以我正在尝试制作一个定时循环,其中不同的文本命令出现在屏幕上,用户必须按下与文本命令对应的键。问题是由于文本居中,它只是在自身上绘制,直到命令不可读。每次我想在窗口中绘制文本时,有没有办法可以清除窗口?我在下面发布了我当前的代码
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
【问题讨论】:
-
您是指“Zelle Graphics”包吗?我不认为 Python dsitributions 中包含标准的“图形”包(至少我得到一个导入错误......)
标签: python text graphics window draw