继续代写Python基础练习题,练习Python的基础使用方法,属于比较基础的Python作业。
Lab Prep 8
Due Date
This is an individual assignment is due by 11:59 pm on the night before your lab. You must complete this assignment on your own.
Using an Entry box
In the past when we wanted to prompt the user for a values, we have used the input() function. This works well in text-based programs, but the challenge is to do this within a Python Graphics window.
The Python Graphics module offers the Entry object type as a way to allow the user to type in Strings allowing them to interact with the program. The Entry object has two parameters: a center Point and a
length. For example, if you wanted to define an Entry box centered at coordinates (100, 20) with a width of 10 characters:
1 | myEntry = Entry(Point(100, 20), 10) |
As with all Graphics objects, the Entry box will need to be drawn after it’s defined. We can use the .getText() function to retrieve the String that has been typed in the Entry box.
1 | myString = myEntry.getText() |
The Assignment
Write a program named labprep8.py that creates a Graphics window matching the example shown here and meet the following parameters:
- All Python commands (except for import)
should be within functions - Include a complete header, including the
program name, your name and a description of
the program’s function - The program should be fully commented with pseudocode throughout
- The Graphics window should be square - with the title What Color, equal x,y dimensions and
a light grey background fill - The Color for next Circle Text label and associated Entry object
- The DRAW control represented by a light green Rectangle
- The QUIT control represented by a red Rectangle
- When a click is detected within the DRAW control:
o If the String obtained from the Entry box is one of the following colors: red, blue, green, yellow, black, purple or pink
o Nothing should happen if the String obtained from the Entry box is not one of those colors§ A _Circle_ with a random radius between 10 - 25 is drawn at a random x,y coordinate within the _Graphics_ window. § The _Circle’s_ fill color should be the _String_ obtained from the _Entry_ box
- When a click is detected within the QUIT control, the Graphics window should close and the program should end without any errors.
1 | An functional example of this program is provided with the Lab Prep 8 assignment on Blackboard |
Submit your completed Lab Prep 8
- Submit your labprep8.py file to Lab Prep 8 on Blackboard
- This assignment is due by 11:59 pm on the night before your lab meeting
- This is an individual assignment – you may not work together
Lab Prep 8 Grading Rubric Points
1 | Program has correct filename labprep8.py, and a complete header as specified 1 |