无法定义顶点

时间:2017-10-15 12:38:46

标签: python python-2.7 python-3.x

我试图以这种方式绘制一个三角形,但是我一直搞乱这个部分,我必须选择我的顶点。有人能告诉我哪里出错了吗?

from graphics import GraphicsWindow

triangle1= [[150,50], [250,50],[200,130]]


win = GraphicsWindow(400, 400)
canvas = win.canvas()
canvas.setOutline("blue")
canvas.drawPolygon(triangle1, canvas)
last = len(triangle1) - 1
for i in range(last):
    start = triangle1[i]
    end = triangle1[i+1]
    canvas.drawLine(start[0], start[1], end[0], end[1])
start =triangle1[last]
end = triangle1[0]
canvas.drawLine(start[0], start[1], end[0], end[1])
win.wait()

1 个答案:

答案 0 :(得分:0)

如果您使用的是EzGraphics,请尝试:

triangle1 = [150, 50, 250, 50, 200, 130]
canvas.drawPolygon(triangle1)

triangle1 = [(150, 50), (250, 50), (200, 130)]
canvas.drawPolygon(triangle1)