我想显示一条消息,并在用户单击时关闭窗口。这应该在圆圈到达窗口底部时发生。我不知道该怎么做,一切正常,直到圆圈通过窗口底部,关闭消息不会弹出并且窗口不会在点击时关闭。我正在使用来自 Zelle for Python 的 graphics.py 图形库。我是 Python 的初学者,所以我现在的知识非常有限。我的代码如下:
from graphics import *
def q2a():
win = GraphWin("window",400,400)
win.setCoords(0,0,400,400)
win.setBackground("light grey")
#drawing circle
circle = Circle(Point(200,100),30)
circle.setFill("red")
circle.draw(win)
#text
message = Text(Point(200,200),"Click Anywhere to Begin")
message.draw(win)
#clicking
while True:
click = win.checkMouse()
if click:
message.undraw()
while circle.getCenter().getY() < 170:
dy=1
dx = 0
dy *=-.01
circle.move(dx,dy)
if circle.getCenter()== 0:
circle.undraw()
gameover = Text(Point(200,200),"Game Over - Click to Close")
gameover.draw(win)
win.checkMouse()
win.close()
q2a()