python 跳动的爱心
时间: 2024-01-23 11:15:37 浏览: 27
以下是一个实现Python跳动的爱心的例子:
```python
import tkinter as tk
def love():
root = tk.Tk()
root.title("跳动的爱心")
root.geometry("400x300")
canvas = tk.Canvas(root, width=400, height=300)
canvas.pack()
def draw_heart(x, y, size):
canvas.create_arc(x, y, x+size, y+size, start=0, extent=180, style='arc', outline='red', width=3)
canvas.create_arc(x+size, y, x+2*size, y+size, start=0, extent=180, style='arc', outline='red', width=3)
canvas.create_line(x, y+size//2, x+2*size, y+size//2, fill='red', width=3)
def animate():
for i in range(100):
canvas.delete("all")
draw_heart(150, 100, 100+i)
root.update()
root.after(10)
animate()
root.mainloop()
love()
```
这段代码使用了`tkinter`模块创建了一个窗口,并在窗口中绘制了一个跳动的爱心。通过不断改变爱心的大小,实现了动画效果。你可以运行这段代码,看到一个跳动的爱心在窗口中显示出来。