ユーザーがウィンドウをクリックするプログラムを作成しようとしています。これにより、ウィンドウにも描画される保存されたポイントのリストが作成されます。ユーザーは何度でもクリックできますが、左下の「完了」と表示されている四角形内をクリックすると、リストが完成します。
ユーザーが「完了」をクリックするまでポイントをプロットできるループの作成に行き詰まりました。
これが私がこれまでに持っているものです(私はたくさん欠けていることを知っています):
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()
グラフィックウィンドウ内でユーザーがクリックして、保存されたポイントのリストを作成する最良の方法は何ですか? これらのポイントは後で使用する予定ですが、最初にポイントを保存したいだけです。