Question

use python This program creates an interactive Line or Polygon drawing app. It creates a blanck...

use python

This program creates an interactive Line or Polygon drawing app.
It creates a blanck white graphics window of size 500 x 500 pixel.
User starts clicking on points in the window.
After clicking first time, a point is drawn at the click location.
After clicking on a second location, a line is drawn from first point to the second location.
This continues, and this way user interactively can draw any kind of line strips or polygon.
If user presses key q, the app will quit.

Homework Answers

Answer #1

I have used the Zelle Python Library for graphics . It is easy to install all you need to store the graphics.py file in the folder where python is installed (Check for official docs to install ) They have provided a nice ppt too .

1. Here , as the first click is made it stores the location , then on second click it creates a line between them , on 3rd click it continues to create a line between 2nd click point and 3rd point .
2. As soon as q key is pressed it waits for a mouse click function (click anywhere in window , window will close down at that moment itself). It is necessary to put a mouse click after pressing q because it according to docs it always wait for a mouse click and responds after that

Code :

from graphics import *

def drawLine(win,p):
p2 = win.getMouse()
line = Line(Point(p.getX(), p.getY()), Point(p2.getX(), p2.getY()))
line.setOutline("black")
line.draw(win)
k = win.checkKey()
if k == 'q':
win.close()
else:
drawLine(win,p2)

win = GraphWin("Window", 500, 500)

p = win.getMouse()
drawLine(win,p)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT