交互式绘制五边形
1 #交互式绘制五边形 2 from graphics import * 3 def main(): 4 win=GraphWin("绘制五边形",300,300) 5 win.setCoords(0.0,0.0,300.0,300.0) 6 message=Text(Point(150,20),"点击五个点") 7 message.draw(win) 8 9 #获得多边形的5个点 10 p1=win.getMouse() 11 p1.draw(win) 12 p2=win.getMouse() 13 p2.draw(win) 14 p3=win.getMouse() 15 p3.draw(win) 16 p4=win.getMouse() 17 p4.draw(win) 18 p5=win.getMouse() 19 p5.draw(win) 20 #使用Polygon对象绘制多边形 21 polygon=Polygon(p1,p2,p3,p4,p5) 22 polygon.setFill("peachpuff") 23 polygon.setOutline("black") 24 polygon.draw(win) 25 #等待响应鼠标事件,退出程序 26 message.setText("Click anywhere to quit.") 27 win.getMouse() 28 29 if __name__=='__main__': 30 main()
运行结果如下: