0
我想创建一个程序,用户在窗口中单击,并创建一个存储点的列表,这些点也绘制在窗口中。用户可以点击任意次数,但是一旦他们在左下角的“完成”矩形内点击,该列表就完成了。在graphics.py窗口中创建鼠标点击绘制点的列表
我已经停留在创建循环,允许用户绘制点直到他们点击“完成”。
这里是我到目前为止(我知道我错过了很多):
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()
什么是图形窗口中创建一个从用户点击保存点的列表的最佳方式?我打算稍后使用这些点,但我只想先获得点数。
过宽和意见为主(以目前的状态)... ...只要创造的鼠标移动/关闭/打开事件,并在一些地方保存列表。我在代码中看不到它。相反,你正在一个循环中投票,这不是一个好主意。添加您正在使用的语言/ IDE和OS标签。我强烈建议看看这个:[简单的拖放示例在C + +/VCL/GDI](http://stackoverflow.com/a/20924609/2521214)与我的简单示例(包括完整的项目+ EXE zip文件),可以添加屏幕上的对象很少,移动它们,删除它们... – Spektre