[英]Unable to display coordinates after polygon drawn in Zelle graphics.py
Am able to successfully draw a polygon using Zelle graphics.py in Python, but I was unable to display the coordinates for the points used. 能够在Python中使用Zelle graphics.py成功绘制多边形,但无法显示所用点的坐标。 How can I get it done using getPoints() only.
我如何仅使用getPoints()完成它。
Here's my code: 这是我的代码:
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()
You can simply do that with print(polygon.getPoints())
in your main method, which gives you [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)]
as output. 您可以在主方法中简单地使用
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)]
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.