我是python的新手,我得到了一个无效的语法(参见下面的错误),我不擅长这个error....help?我正在编写代码,在4个点击建造一所房子。下面的很多代码都是我尝试不同的东西,所以忽略它(或者给我应该做什么的建议),这是p2错误让我困惑的地方。
<using graphics.py>
import graphics
from graphics import*
def house():
win=GraphWin(800,500)
win.setCoords(0.0,0.0,4.0,4.0)#reset coordinates
Text(Point(2.0,3.5),"click spot to designate 2 corners of house").draw(win)
p1=win.getMouse()
p1.draw(win)
side1=(Point(p1.getX(),(p1.getY()))
p2=win.getMouse()<----------------------------ERROR with the p2
p2.draw(win)
side2=(Point(p2.getX(),(p2.getY()))
rect = Rectangle(side1,side2)
rect.draw(win)
#door- p3=center top edge of door
msg2 = Text(Point(2.0,0.5),"click to designate top of door")
msg2.draw(win)
p3=win.getMouse()
p3.draw(win)
#golden:)
Line(Point(p3.getX(),(p3.getY())),(Point(p2.getX()),(p2.getY()))).draw(win)
"""
p3 = dwidth.getCenter()
rectWidth = (p2.getX()) - (p1.getX())
#doorWidth = door.setWidth(distance/5.0)#width 1/5 of house
dwidth= eval((rectWidth) / (5))
dheight=((getP3(),(getP2()))#height = from top corners to bottom of the frame
#door = Rectangle((dwidth) * (dheight))"""
#door.draw(win)
"""#Window
message3 = Text(Point(2.0, 1.0),"click to designate center of square window").draw(win)
p4=win.getMouse()
p4.draw(win)
c=door.getCenter()
dx=p4.getX()-c.getX()
dy=p4.getY()-c.getY()
window = Rectangle(Point(dx,dx),Point(dy,dy))
window.draw(win)
#window side = half of door with
#roof top = half way btwn l and r edges
#house height = half height of house frame
#win.getMouse()
#win.close
"""
#window one forth of the door
#window = Rectangle(p4)
#window.setWidth(doorwidth/ 4.0)
#window.draw(win)
house()
>>> ================================ RESTART ================================
>>>
Traceback (most recent call last):
File "E:\ICS 140\ass 8.py", line 57, in <module>
house()
File "E:\ICS 140\ass 8.py", line 28, in house
Line(Point(p3.getX()),(p3.getY()),(Point(p2.getX()),(p2.getY()))).draw(win)
TypeError: __init__() missing 1 required positional argument: 'y'
>>> 发布于 2014-12-01 05:07:48
之所以会出现这个错误,是因为Point需要一个x和一个y参数,而您只在尝试创建x的那一行中传递了一个Rectangle。
不是很确定你的代码想要做什么,但希望这能帮助你朝着正确的方向开始:
from graphics import *
def house():
win=GraphWin(800,500)
win.setCoords(0.0,0.0,3.0,4.0)#reset coordinates
Text(Point(1.5,3.5),"click spot to designate 2 corners of house").draw(win)
p1 = win.getMouse()
p1.draw(win)
p2 = win.getMouse()
p2.draw(win)
rectangle = Rectangle(p1, p2)
rectangle.setWidth(3)
rectangle.draw(win)
win.getMouse()
win.close()
house()https://stackoverflow.com/questions/27217593
复制相似问题