用turtle画小黄人,两个标签控件label,三个按钮button,分别使人物眨眼,动脚,改变颜色
时间: 2024-05-25 12:06:25 浏览: 119
以下是用turtle画小黄人,两个标签控件label,三个按钮button,分别使人物眨眼,动脚,改变颜色的Python代码:
```python
import turtle
# 画小黄人的函数
def draw_minion():
# 设置画笔颜色和填充颜色
turtle.pencolor("#000000")
turtle.fillcolor("#FCD12A")
turtle.begin_fill()
# 画身体
turtle.circle(100)
turtle.end_fill()
# 画眼睛
turtle.pencolor("#000000")
turtle.fillcolor("#FFFFFF")
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.goto(40, 120)
turtle.dot(10)
turtle.goto(-40, 120)
turtle.dot(10)
# 画嘴巴
turtle.pencolor("#000000")
turtle.up()
turtle.goto(-60, 85)
turtle.down()
turtle.goto(60, 85)
turtle.goto(80, 60)
turtle.goto(60, 40)
turtle.goto(-60, 40)
turtle.goto(-80, 60)
turtle.goto(-60, 85)
# 画手
turtle.pencolor("#000000")
turtle.up()
turtle.goto(-100, 0)
turtle.down()
turtle.goto(-120, -60)
turtle.goto(-80, -80)
turtle.goto(-60, -120)
turtle.up()
turtle.goto(100, 0)
turtle.down()
turtle.goto(120, -60)
turtle.goto(80, -80)
turtle.goto(60, -120)
# 眨眼的函数
def blink():
turtle.pencolor("#000000")
turtle.fillcolor("#FFFFFF")
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.goto(40, 120)
turtle.dot(10)
turtle.goto(-40, 120)
turtle.dot(10)
# 动脚的函数
def move_feet():
turtle.pencolor("#000000")
turtle.up()
turtle.goto(-100, -120)
turtle.down()
turtle.goto(-120, -180)
turtle.goto(-80, -200)
turtle.goto(-60, -240)
turtle.up()
turtle.goto(100, -120)
turtle.down()
turtle.goto(120, -180)
turtle.goto(80, -200)
turtle.goto(60, -240)
# 改变颜色的函数
def change_color():
turtle.pencolor("#FF0000")
turtle.fillcolor("#00FF00")
turtle.begin_fill()
turtle.circle(100)
turtle.end_fill()
# 创建窗口和控件
win = turtle.Screen()
win.setup(500, 500)
win.title("小黄人")
# 画小黄人
draw_minion()
# 创建按钮和标签
blink_button = turtle.Turtle()
blink_button.up()
blink_button.goto(-200, 200)
blink_button.write("眨眼", font=("Arial", 16, "normal"))
blink_button.onclick(blink)
move_button = turtle.Turtle()
move_button.up()
move_button.goto(0, 200)
move_button.write("动脚", font=("Arial", 16, "normal"))
move_button.onclick(move_feet)
color_button = turtle.Turtle()
color_button.up()
color_button.goto(200, 200)
color_button.write("改变颜色", font=("Arial", 16, "normal"))
color_button.onclick(change_color)
turtle.done()
```
阅读全文