Complete the following incomplete program (begin by copy-pasting that into a new program file). The completed program will provide a user interface to draw as many circles as the user wants only by clicking in the window. After getting the number of circles (n) to draw as input from the user through the provided interface, the program should iterate n times. In each iteration it should wait for the user to click twice and draw a circle with center at the point where the user clicked first and with radius calculated as its distance from the second point where the user clicked. It should then fill the circle with a random color. Hints: Distance between two points with coordinates x1 & y1 and x2 & y2 and can be calculated as sqrt((x1-x2)2 + (y1-y2)2 ). To generate a random color, use randint(0,255) from the random libray to generate a random number between 0 and 255 (both inclusive). Use it three times to get the r, g and b values to generate a random color from graphics import * from math import sqrt from random import randint def main() :     win = GraphWin("Circles", 500, 500)     text1 = Text(Point(152,20),"How many circles do you want to draw:")     text2 = Text(Point(120,60),"Click anywhere after entering.")     text1.draw(win)     text2.draw(win)     nbox = Entry(Point(40,40),4)     nbox.draw(win)          win.getMouse()     n = int(nbox.getText())     text2.undraw()     nbox.undraw()     text1.setText("Click twice to draw each circle.")     # complete the rest of the program          # to end the window     text1.setText("Click anywhere to quit.")     win.getMouse()     win.close() main()

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Topic Video
Question

Complete the following incomplete program (begin by copy-pasting that into a new program file). The completed program will provide a user interface to draw as many circles as the user wants only by clicking in the window. After getting the number of circles (n) to draw as input from the user through the provided interface, the program should iterate n times. In each iteration it should wait for the user to click twice and draw a circle with center at the point where the user clicked first and with radius calculated as its distance from the second point where the user clicked. It should then fill the circle with a random color.

Hints:

  • Distance between two points with coordinates x1 & y1 and x2 & y2 and can be calculated as sqrt((x1-x2)2 + (y1-y2)2 ).
  • To generate a random color, use randint(0,255) from the random libray to generate a random number between 0 and 255 (both inclusive). Use it three times to get the r, g and b values to generate a random color

from graphics import *
from math import sqrt
from random import randint

def main() :
    win = GraphWin("Circles", 500, 500)
    text1 = Text(Point(152,20),"How many circles do you want to draw:")
    text2 = Text(Point(120,60),"Click anywhere after entering.")
    text1.draw(win)
    text2.draw(win)
    nbox = Entry(Point(40,40),4)
    nbox.draw(win)
    
    win.getMouse()
    n = int(nbox.getText())

    text2.undraw()
    nbox.undraw()

    text1.setText("Click twice to draw each circle.")

    # complete the rest of the program
    


    # to end the window
    text1.setText("Click anywhere to quit.")
    win.getMouse()
    win.close()


main()

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Instruction Format
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education