能够在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()
答案 0 :(得分:0)
您可以在main方法中使用print(polygon.getPoints())
执行此操作,这会将[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()