#Nicolas Conde COMP 151-005 10-3-17
from graphics import *
def main():
#DataStorage
NumberOfShapes = 0.0
ShapeType = 0.0
ShapeSpecs = 0.0
p1 = 0.0
p2 = 0.0
#GraphicsWindow
win = GraphWin("Drawing Shapes", 500, 500)
#Input
print("*** Drawing Shapes ***")
NumberOfShapes = int(input("Select the number of shapes: "))
#For loops begin here, each shape has their own for loop. Anything that is a commment within the for loop is from checkpoint 1 of the project.
for i in range (NumberOfShapes):
ShapeType = input("Select the shape type: ")
#Rectangle
if ShapeType == "R":
ShapeSpecs = print("Click your mouse on the upper left and lower right points of the rectangle): ")
p1 = win.getMouse()
p2 = win.getMouse()
#ShapeSpecs = ShapeSpecs.split(',')
Rect = Rectangle(p1,p2) #(Point(int(ShapeSpecs[0]),int(ShapeSpecs[1])), Point(int(ShapeSpecs[2]),int(ShapeSpecs[3])))
Rect.draw(win)
#Oval
if ShapeType == "O":
ShapeSpecs = print("Click your mouse on the upper left and lower right points of the oval): ")
p1 = win.getMouse()
p2 = win.getMouse()
#ShapeSpecs = ShapeSpecs.split(',')
Ovl = Oval(p1,p2) #(Point(int(ShapeSpecs[0]),int(ShapeSpecs[1])), Point(int(ShapeSpecs[2]),int(ShapeSpecs[3])))
Ovl.draw(win)
#Circle
if ShapeType == "C":
ShapeSpecs = int("Enter the radius: ")
ShapeSpecs = print("Click your mouse on the center of the circle: ")
p1 = win.getMouse()
#ShapeSpecs = ShapeSpecs.split(',')
Circ = Circle #(Point(int(ShapeSpecs[0]), int(ShapeSpecs[1])), float(ShapeSpecs[2]))
Circ.draw(win)
这是第一个问题
Traceback (most recent call last):
File "C:/Users/nicol/OneDrive - Bridgewater State University/Freshman Year 2017/Semester 1/Computer Science I - COMP 151 - 005 Haleh Khojasteh/Project-2-Drawing Shapes/NicolasCondeProject2.py", line 91, in <module>
main()
File "C:/Users/nicol/OneDrive - Bridgewater State University/Freshman Year 2017/Semester 1/Computer Science I - COMP 151 - 005 Haleh Khojasteh/Project-2-Drawing Shapes/NicolasCondeProject2.py", line 46, in main
ShapeSpecs = int("Enter the radius: ")
ValueError: invalid literal for int() with base 10: 'Enter the radius: '
继续代码:
#Line
if ShapeType == "L":
ShapeSpecs = print("Click your mouse on two points of the line): ")
p1 = win.getMouse()
p2 = win.getMouse()
#ShapeSpecs = ShapeSpecs.split(',')
Lin = Line(p1,p2) #(Point(int(ShapeSpecs[0]), int(ShapeSpecs[1])), Point(int(ShapeSpecs[2]), int(ShapeSpecs[3])))
Lin.draw(win)
#Text
if ShapeType == "T":
ShapeSpecs = input("Enter the text: ")
ShapeSpecs = print("Click your mouse on the center of the text: ")
p1 = win.getMouse()
#ShapeSpecs = ShapeSpecs.split(',')
Txt = Text(p1) #(Point(int(ShapeSpecs[0]), int(ShapeSpecs[1])), (ShapeSpecs[2]))
Txt.draw(win)
这是第二个问题
Traceback (most recent call last):
File "C:/Users/nicol/OneDrive - Bridgewater State University/Freshman Year 2017/Semester 1/Computer Science I - COMP 151 - 005 Haleh Khojasteh/Project-2-Drawing Shapes/NicolasCondeProject2.py", line 77, in <module>
main()
File "C:/Users/nicol/OneDrive - Bridgewater State University/Freshman Year 2017/Semester 1/Computer Science I - COMP 151 - 005 Haleh Khojasteh/Project-2-Drawing Shapes/NicolasCondeProject2.py", line 63, in main
Txt = Text(p1) #(Point(int(ShapeSpecs[0]), int(ShapeSpecs[1])), (ShapeSpecs[2]))
TypeError: __init__() missing 1 required positional argument: 'text'
继续代码:
#Point
if ShapeType == "P":
ShapeSpecs = print("Click your mouse on the point location: ")
p1 = win.getMouse()
#ShapeSpecs = ShapeSpecs.split(',')
Pnt = Point(p1) #(int(ShapeSpecs[0]), int(ShapeSpecs[1]))
Pnt.draw(win)
win.getMouse()
win.close()
main()
答案 0 :(得分:0)
您正在使用int
,就像它与input
ShapeSpecs = int("Enter the radius: ")
它应该是两个嵌套调用:
ShapeSpecs = int(input("Enter the radius: "))
此逻辑会覆盖用户输入,无法将文本传递给Text()
:
ShapeSpecs = input("Enter the text: ")
ShapeSpecs = print("Click your mouse on the center of the text: ")
p1 = win.getMouse()
Txt = Text(p1)
而是尝试:
ShapeText = input("Enter the text: ")
ShapeSpecs = print("Click your mouse on the center of the text: ")
p1 = win.getMouse()
Txt = Text(p1, ShapeText)
你在圈子逻辑中犯了类似的错误:
ShapeSpecs = int("Enter the radius: ")
ShapeSpecs = print("Click your mouse on the center of the circle: ")
p1 = win.getMouse()
Circ = Circle
Circ.draw(win)
在您使用它之前覆盖半径:
ShapeRadius = int("Enter the radius: ")
ShapeSpecs = print("Click your mouse on the center of the circle: ")
p1 = win.getMouse()
Circ = Circle(p1, ShapeRadius)
Circ.draw(win)