在Python中画国旗再在中间打上字,
时间: 2024-04-28 16:14:39 浏览: 17
以下是在Python中画中国国旗并在中间打上“祖国万岁”的代码:
```
import turtle
# 设置画布大小和背景色
turtle.setup(800, 600)
turtle.bgcolor('red')
# 画五角星
turtle.penup()
turtle.goto(-100, 60)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(200)
turtle.right(144)
turtle.end_fill()
# 画四个小五角星
turtle.penup()
turtle.goto(-40, 100)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(80)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(50, 100)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(80)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-40, 0)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(80)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(50, 0)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(80)
turtle.right(144)
turtle.end_fill()
# 写字
turtle.penup()
turtle.goto(0, -150)
turtle.pencolor('yellow')
turtle.write('祖国万岁', align='center', font=('Arial', 36, 'normal'))
# 隐藏画笔
turtle.hideturtle()
# 点击关闭窗口
turtle.exitonclick()
```
运行结果如下图所示:
![image](https://cdn.luogu.com.cn/upload/image_hosting/ed9f2g9e.png)
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)