2

我能够在 Python 中使用 Zelle graphics.py 成功绘制多边形,但我无法显示所用点的坐标。如何仅使用 getPoints() 完成它。

这是我的代码:

import math
import graphics #must be included
from graphics import* # must be included

def main():
    win = graphics.GraphWin("Exercise 2, Polygon", 500, 500)
    #denotes window size

    win.setBackground("black")

    polygon = Polygon(Point(60,80),Point(50,70),Point(70,20),Point(90,50),Point(100,80))
    #Include "Point" in the statement, else it wouldn't work
    polygon.setOutline("yellow")
    polygon.setWidth(5)
    polygon.draw(win)


main()
4

1 回答 1

0

您可以简单地print(polygon.getPoints())在您的 main 方法中执行此操作,该方法为您[Point(60.0, 80.0), Point(50.0, 70.0), Point(70.0, 20.0), Point(90.0, 50.0), Point(100.0, 80.0)]提供输出。

示例代码:

import math
import graphics #must be included
from graphics import* # must be included

def main():
    win = graphics.GraphWin("Exercise 2, Polygon", 500, 500)
    #denotes window size

    win.setBackground("black")

    polygon = Polygon(Point(60,80),Point(50,70),Point(70,20),Point(90,50),Point(100,80))
    #Include "Point" in the statement, else it wouldn't work
    polygon.setOutline("yellow")
    polygon.setWidth(5)
    polygon.draw(win)

    print(polygon.getPoints())    

main()
于 2018-02-27T10:36:54.147 回答