Pergunta

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. How can I get it done using getPoints() only.

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()

Nenhuma solução correta

Outras dicas

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.

Example 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)

    print(polygon.getPoints())    

main()
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top