我正在尝试创建一个用户在窗口中单击的程序,这将创建一个存储点列表,这些点也绘制在窗口中。用户可以根据需要单击任意多次,但是一旦在左下角标有“完成”的矩形内单击,列表就完成了。
我一直坚持创建允许用户绘制点的循环,直到他们单击“完成”。
这是我到目前为止所拥有的(我知道我错过了很多):
from graphics import *
def main():
plot=GraphWin("Plot Me!",400,400)
plot.setCoords(0,0,4,4)
button=Text(Point(.3,.2),"Done")
button.draw(plot)
Rectangle(Point(0,0),Point(.6,.4)).draw(plot)
#Create as many points as the user wants and store in a list
count=0 #This will keep track of the number of points.
xstr=plot.getMouse()
x=xstr.getX()
y=xstr.getY()
if (x>.6) and (y>.4):
count=count+1
xstr.draw(plot)
else: #if they click within the "Done" rectangle, the list is complete.
button.setText("Thank you!")
main()
通过用户在图形窗口中单击来创建存储点列表的最佳方法是什么?我计划稍后使用这些积分,但我只想先存储积分。