【发布时间】:2017-06-08 16:40:04
【问题描述】:
我想删除以图形方式显示的文本,以便编写新文本而不会重叠。我在下面包含了我的代码。再次感谢您的宝贵时间。
from graphics import*
import random
# Function for winning
def youwin():
txt = Text(Point(250,100), "You are a Winner!")
txt.setTextColor(color_rgb(0,255,200))
txt.setSize(30)
txt.setFace('courier')
txt.draw(win)
# Function for losing
def youlose():
txt= Text(Point(250,100), "You are a Loser!")
txt.setTextColor(color_rgb(0,255,0))
txt.setSize(30)
txt.setFace('courier')
txt.draw(win)
# Sets a Window
win = GraphWin("My Window", 800, 600)
win.setBackground('White')
# loops 10 Times and picks out 3 random gif's.
# Then displays each image on the screen in a row.
for x in range(10):
cards = ["1.png","2.png","3.png"]
rand_card1 = random.choice(cards)
img1 = Image(Point(100, 250), rand_card1)
rand_card2 = random.choice(cards)
img2 = Image(Point(300, 250), rand_card2)
rand_card3 = random.choice(cards)
img3 = Image(Point(500, 250), rand_card3)
img1.draw(win)
img2.draw(win)
img3.draw(win)
# checks to see if you are a winner
if rand_card1 == rand_card2 and rand_card2 == rand_card3:
youwin()
else:
youlose()
# waits for a mouse click. In the future this will be a button.
win.getMouse()
img1.undraw()
img2.undraw()
img3.undraw()
#win.close()#
这是我目前得到的输出:
【问题讨论】:
-
我对你使用的东西不是很熟悉,但我想你可能想以某种方式清除你的绘图区域在在那里绘制新文本。我会寻找屏幕清除功能或在与背景颜色相同的旧文本上绘制一个矩形。也许比我更有知识的人会明白我在说什么,并在下面发布所需的确切代码......但这就是我的一般方法。
-
谢谢你,克里斯,矩形工作!我确信我的编码效率不高,但作为一个新手,我会尽我所能:) 你能把你的评论变成答案,这样我就可以投票了吗?
标签: python python-3.x text zelle-graphics