用tkinter画布,随便画一个复杂的风景图的代码
时间: 2024-04-18 21:32:11 浏览: 106
当然,下面是一个简单的例子,可以用tkinter绘制一个复杂的风景图:
```python
import tkinter as tk
# 创建窗口
window = tk.Tk()
window.title("复杂风景图")
window.geometry("800x600")
# 创建画布
canvas = tk.Canvas(window, width=800, height=600)
canvas.pack()
# 绘制背景
canvas.create_rectangle(0, 0, 800, 600, fill="sky blue")
# 绘制太阳
canvas.create_oval(700, 50, 750, 100, fill="yellow", outline="yellow")
# 绘制草地
canvas.create_rectangle(0, 400, 800, 600, fill="green", outline="green")
# 绘制树干
canvas.create_rectangle(100, 300, 120, 400, fill="brown", outline="brown")
# 绘制树冠
canvas.create_polygon(80, 300, 140, 300, 110, 250, fill="green", outline="green")
# 绘制房子
canvas.create_rectangle(400, 300, 600, 500, fill="beige", outline="black")
canvas.create_polygon(400, 300, 600, 300, 500, 200, fill="beige", outline="black")
# 绘制窗户
canvas.create_rectangle(450, 350, 500, 400, fill="white", outline="black")
canvas.create_rectangle(550, 350, 600, 400, fill="white", outline="black")
# 绘制门
canvas.create_rectangle(500, 450, 550, 500, fill="brown", outline="black")
# 绘制云朵
canvas.create_oval(200, 100, 300, 150, fill="white", outline="white")
canvas.create_oval(250, 100, 350, 150, fill="white", outline="white")
canvas.create_oval(300, 100, 400, 150, fill="white", outline="white")
# 运行窗口
window.mainloop()
```
运行以上代码,将会弹出一个窗口,显示出一个简单的复杂风景图。你可以根据自己的需要修改代码来绘制更加复杂的风景图。
阅读全文