Question

In: Computer Science

Python: I am making a program that prints a circle of random size, random location, with...

Python: I am making a program that prints a circle of random size, random location, with user_inputed (using entry) color, when 'DRAW' button is clicked.

I am stuck on passing variables on the while loop. Please Help

from graphics import*
import sys
import random

from time import sleep

def main():
win = GraphWin ('What Color', 500, 600)
win.setCoords(0, 0, 500, 600)

DB = Rectangle(Point(350, 580), Point(400, 560))
DB.setFill('light Green')
DB.draw(win)

QB = Rectangle(Point(430, 580), Point(480, 560))
QB.setFill('red')
QB.draw(win)

DB_t = Text(Point(375,570),'DRAW')
DB_t.setSize(10)
DB_t.draw(win)

QB_t = Text(Point(455,570),'QUIT')
QB_t.setSize(10)
QB_t.draw(win)
  

Ins_t = Text(Point(125, 570), 'Color for next Circle:')
Ins_t.setSize(10)
Ins_t.draw(win)

E1 = Entry(Point(215, 570), 5)
E1.setFill('white')
E1.draw(win)

size = random.randrange (10,25)
x = random.randrange(5, 495)
y = random.randrange(5, 595)
  
while True:
for i in circle(colors):
if circle(color_ui) == i:
c = Circle(Point(x,y), size)
c.setFill(i)
  
while True:
m = win.checkMouse()
if m:
if 430 < m.getX() < 480 and 560 < m.getY() < 580:
win.close()
if 350 < m.getX() < 400 and 560 < m.getY() < 580:
if E1.getText():
c.draw(win)

def circle(c, E1):
colors = ['red','blue','green','yellow','black','purple','pink']
color_ui = E1.getText
while True:
for i in colors:
if color_ui == i:
return i
colors, color_ui


  

Solutions

Expert Solution

# do comment if any problem arises

# Code

from graphics import*

import sys

import random

from time import sleep


def main():

    win = GraphWin('What Color', 500, 600)

    win.setCoords(0, 0, 500, 600)

    DB = Rectangle(Point(350, 580), Point(400, 560))

    DB.setFill('light Green')

    DB.draw(win)

    QB = Rectangle(Point(430, 580), Point(480, 560))

    QB.setFill('red')

    QB.draw(win)

    DB_t = Text(Point(375, 570), 'DRAW')

    DB_t.setSize(10)

    DB_t.draw(win)

    QB_t = Text(Point(455, 570), 'QUIT')

    QB_t.setSize(10)

    QB_t.draw(win)

    Ins_t = Text(Point(125, 570), 'Color for next Circle:')

    Ins_t.setSize(10)

    Ins_t.draw(win)

    E1 = Entry(Point(215, 570), 5)

    E1.setFill('white')

    E1.draw(win)

    oldc = None

    while True:

        size = random.randrange(10, 25)

        x = random.randrange(5, 495)

        y = random.randrange(5, 595)

        c = Circle(Point(x, y), size)

        m = win.checkMouse()

        if m:

            if oldc != None:

                oldc.undraw()

            if 430 < m.getX() < 480 and 560 < m.getY() < 580:

                win.close()

            if 350 < m.getX() < 400 and 560 < m.getY() < 580:

                if E1.getText():

                    c.setFill(E1.getText())

                    c.draw(win)

                    # save old circle

                    oldc = c


def circle(c, E1):

    colors = ['red', 'blue', 'green', 'yellow', 'black', 'purple', 'pink']

    color_ui = E1.getText

    for i in colors:

        if color_ui == i:

            return i

    return -1

main()

Screenshot:

Output:


Related Solutions

I am having a trouble with a python program. I am to create a program that...
I am having a trouble with a python program. I am to create a program that calculates the estimated hours and mintutes. Here is my code. #!/usr/bin/env python3 #Arrival Date/Time Estimator # # from datetime import datetime import locale mph = 0 miles = 0 def get_departure_time():     while True:         date_str = input("Estimated time of departure (HH:MM AM/PM): ")         try:             depart_time = datetime.strptime(date_str, "%H:%M %p")         except ValueError:             print("Invalid date format. Try again.")             continue        ...
(Display a Circle and Its Attributes) Write a program that displays a circle of random size...
(Display a Circle and Its Attributes) Write a program that displays a circle of random size and calculates and displays the area, radius, diameter and circumference. Use the following equations: diameter = 2 × radius, area = π × radius2, circumference = 2 × π × radius. Use the constant Math.PI for pi (π). All drawing should be done on a subclass of JPanel, and the results of the calculations should be displayed in a read-only JTextArea.
This is in Python I am getting an error when I run this program, also I...
This is in Python I am getting an error when I run this program, also I cannot get any output. Please help! #Input Section def main(): name=input("Please enter the customer's name:") age=int(input("Enter age of the customer: ")) number_of_traffic_violations=int(input("Enter the number of traffic violations: ")) if age <=15 and age >= 105: print('Invalid Entry') if number_of_traffic_violations <0: print('Invalid Entry') #Poccessing Section def Insurance(): if age < 25 and number_of_tickets >= 4 and riskCode == 1: insurancePrice = 480 elif age >=...
Python program to simulate estimate the probability that a random chord on a unit-circle (radius one),...
Python program to simulate estimate the probability that a random chord on a unit-circle (radius one), exceeds the radius of the circle? Repeat the experiment of generating random chords 1,000 times. Record the estimate of the probability that the chord length exceeds the radius Please use comments to help explain
Circle Object Python program Compute the area and perimeter of a circle using Python classes. take...
Circle Object Python program Compute the area and perimeter of a circle using Python classes. take the radius from the user and find the area and perimeter of a circle please use comments to explain so i better understand
I am trying to make a program in Python that opens a file and tells you...
I am trying to make a program in Python that opens a file and tells you how many lines, vowels, consonants, and digits there are in the file. I got the print out of lines, digits, and consonants, but the if statement I made with the vowels list isn't recognizing them. How can I make the vowels go through the if statement with the list? Am I using the wrong operator? Here is my program #Assignment Ch7-1 #This program takes...
I am creating a program in Python that allows the user to input a credit card...
I am creating a program in Python that allows the user to input a credit card number, and determine if the card is valid. This should be done by taking every other number, starting from the right, and adding them together. The doubling each of the other digits, and adding them together as single digits, and then adding the two sums together. For example, if the number 4833 1200 3412 3456 is used, the first sum should be 6+4+2+4+0+2+3+8=29, the...
This is a Java program that I am having trouble making. 1- Search for the max...
This is a Java program that I am having trouble making. 1- Search for the max value in the linked list. 2- Search for the min value in the linked list. 3- Swap the node that has the min data value with the max one. (Note: Move the nodes to the new positions). 4- Add the min value and the max value and insert the new node with the calculated value before the last node. I already made a generic...
I am so lost on this. I am making a B in this class but I...
I am so lost on this. I am making a B in this class but I can not seem to get this project completed. Please help. ACC-120 Project – Financial Accounting This assignment supports the following outcomes: ·          Prepare journal and ledger entries for a service or merchandising business. ·          Prepare year-end statements for a service or merchandising business. ·          Report cost decisions using accounting principles and financial statement analysis. ·          Evaluate how knowledge, skills, and attitudes learned in this...
Can you write this program, but in python, I just wanna see what am I doing...
Can you write this program, but in python, I just wanna see what am I doing wrong. thank you Instructions: The Gas-N-Clean Service Station sells gasoline and has a car wash. Fees for the car wash are $1.25 with a gasoline purchase of $10.00 or more and $3.00 otherwise. Three kinds of gasoline are available: regular at $2.89, plus at $3.09, and super at $3.39 per gallon. User Request: Write a program that prints a statement for a customer. Analysis:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT