无法通过分割直线的长度并将其设置为半径来创建圆半径

  • 本文关键字:设置 创建 分割 python graphics
  • 更新时间 :
  • 英文 :


我需要将我正在制作的圆的半径设置为之前制作的直线长度的1/4。

win = GraphWin("Interactive Drawing",300,300)
win.setCoords(0,0,300,300)
##Create instruction to click the corners of the rectangle
instruction1 = Text(Point(104,10), "Click for lower left of rectangle")
instruction1.draw(win)
lowerLeft = win.getMouse()
instruction1.undraw()
instruction2 = Text(Point(100,10), "Click upper right of rectangle")
instruction2.draw(win)
upperRight = win.getMouse()
instruction2.undraw()
##Draw 2 triangles to form a multicolor rectangle from given points
rightX = upperRight.getX()
rightY = upperRight.getY()
leftX = lowerLeft.getX()
leftY = lowerLeft.getY()
leftZ = rightY - leftY
leftB = leftY + leftZ
rightZ = rightY - leftZ
point1 = Point(leftX,leftY)
point2 = Point(leftX,leftB)
point3 = Point(rightX,rightY)
point4 = Point(rightX,rightZ)

leftTriangle = Polygon(point1,point2,point3)
leftTriangle.draw(win)
leftTriangle.setFill("Purple")
rightTriangle = Polygon(point1,point3,point4)
rightTriangle.draw(win)
rightTriangle.setFill("Green")
##Get Circle point from mouse and draw 4 from point
color = Entry(Point(90,30),19)
color.setText("Enter Color Name Here")
color.draw(win)
instruction3 = Text(Point(114,10), "Click location after entering color")
instruction3.draw(win)
circleClick = win.getMouse()
instruction3.undraw()
circleX = circleClick.getX
circleY = circleClick.getY
circleCenter = Point(circleX,circleY)
radius = ((rightY - leftY)/4)
circle1 = Circle(circleCenter, radius)
circle1.draw(win)
circle2 = Circle(300 - circleClick.getX, 300 - circleClick.getY,radius)
circle2.draw(win)

当我运行程序时,我可以制作矩形,但当要求鼠标点击点作为圆心并试图绘制时,我得到了错误

  File "C:/Users/Ian/Documents/Python Projects/InputDrawing.py", line 68, in main
    circle1 = Circle(circleCenter, radius)
  File "C:UsersIanAppDataLocalProgramsPythonPython35-32libgraphics.py", line 599, in __init__
    p1 = Point(center.x-radius, center.y-radius)
TypeError: unsupported operand type(s) for -: 'method' and 'float'

我不知道如何将它们转化为可以分割在一起的东西,以获得圆的半径。有什么帮助吗?(如果这有意义的话哈哈)

在整个代码中有几次使用.getX.getY。这意味着您将获得函数getXgetY,而不是值xy

要解决此问题,请使用()调用函数。

当前导致错误的原因是以下几行:

circleX = circleClick.getX
circleY = circleClick.getY

将它们切换到:

circleX = circleClick.getX()
circleY = circleClick.getY()

您还需要更改线路:

circle2 = Circle(300 - circleClick.getX, 300 - circleClick.getY,radius)

至:

circle2 = Circle(300 - circleClick.getX(), 300 - circleClick.getY(),radius)

这一行目前不会给你带来问题,但一旦你修复了第一个错误,它就会出现。

相关内容

  • 没有找到相关文章

最新更新