代码如下:
1 from graphics import * 2 win=GraphWin("绘制卡通脸",200,200)#绘制窗口 3 face=Circle(Point(100,95),50)#定义脸的圆心和半径 4 leftEye=Circle(Point(80,80),5)#定义左眼的圆心和半径 5 leftEye.setFill("yellow")#左眼填充颜色 6 leftEye.setOutline("red")#左眼外部线条 7 rightEye=Circle(Point(120,80),5) 8 rightEye.setFill("yellow") 9 rightEye.setOutline("red") 10 mouth=Line(Point(80,110),Point(120,110))#定义嘴的起止点 11 12 #以下是在窗口绘制 13 face.draw(win) 14 mouth.draw(win) 15 leftEye.draw(win) 16 rightEye.draw(win)
效果图: