python动态爱心代码加名字
时间: 2023-11-17 22:02:14 浏览: 238
以下是Python动态爱心代码加名字的示例:
```python
from tkinter import *
import math
root = Tk()
root.geometry("800x600")
root.title("Dynamic Heart")
canvas = Canvas(root, width=800, height=600, bg="black")
canvas.pack()
text = Label(root, text="By SilverPriest ᏊˊꈊˋᏊ", font=("Helvetica", 18), fg="#c12bec", bg="black")
text.place(x=650, y=500)
name = Label(root, text="Your Name", font=("Helvetica", 18), fg="#c12bec", bg="black")
name.place(x=350, y=500)
def create_heart(x, y, size):
canvas.create_arc(x, y, x+size, y+size, start=150, extent=60, fill="#ff6b6b", outline="")
canvas.create_arc(x+size, y, x+2*size, y+size, start=210, extent=60, fill="#ff6b6b", outline="")
canvas.create_polygon(x, y+size/2, x+size/2, y+size, x+size, y+size/2, x+size/2, y, fill="#ff6b6b", outline="")
def move_heart():
x = 400 + 200 * math.sin(angle)
y = 300 + 200 * math.cos(angle)
canvas.delete("all")
create_heart(x, y, 100)
text.place(x=x-50, y=y+50)
name.place(x=x-50, y=y+80)
global angle
angle += 0.03
root.after(10, move_heart)
angle = 0
move_heart()
root.mainloop()
```
阅读全文