python清除运行窗_在Python中清除窗口中的图形

所以我试着做一个定时循环,不同的文本命令出现在屏幕上,用户必须按与文本命令对应的键。问题是因为文本是居中的,所以它只是在命令无法读取之前自动绘制。有没有一种方法可以在每次我想在窗口上绘制文本时清除窗口?我在下面发布了我当前的代码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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值