Python表白代码高级可复制(直接复制可用,三种风格任选)

运行环境:Python3,无需复杂配置,部分效果需要安装库,指令一并附上

第一种|动态爱心(图形界面·高级动画,推荐)

效果:窗口弹出跳动爱心,附带文字告白,色彩渐变

第一步安装依赖

打开命令提示符执行:

pip install turtle

完整可复制代码

import turtle
import time

# 设置窗口
t = turtle.Turtle()
turtle.setup(width=600, height=600)
turtle.title("致我喜欢的人")
t.speed(0)
t.hideturtle()
t.getscreen().bgcolor("#0a0a1a")

# 爱心绘制函数
def heart(x, y, size):
    t.penup()
    t.goto(x, y)
    t.pendown()
    t.color("#ff4477", "#ff2255")
    t.begin_fill()
    t.left(140)
    t.forward(size)
    t.circle(-size//2, 200)
    t.left(120)
    t.circle(-size//2, 200)
    t.forward(size)
    t.end_fill()

# 跳动动画
scale = 180
for i in range(12):
    t.clear()
    heart(0, -scale//2, scale)
    # 表白文字
    t.penup()
    t.goto(0, -scale//2 - 40)
    t.color("white")
    t.write("我喜欢你", align="center", font=("微软雅黑", 22, "bold"))
    t.goto(0, -scale//2 - 80)
    t.write("往后岁岁年年,只想与你相伴", align="center", font=("微软雅黑", 13))
    # 缩放实现跳动
    if i % 2 == 0:
        scale = 190
    else:
        scale = 170
    turtle.update()
    time.sleep(0.3)

turtle.done()

第二种|控制台文字流星雨表白(终端炫酷款,无需额外库)

直接运行,黑窗口文字特效,全Python内置库,零安装

import random
import time
import os

# 适配Windows控制台清屏
def clear_screen():
    os.system("cls")

words = "我喜欢你,不止今天,而是朝朝暮暮"
width = 60
height = 20
cols = [random.randint(-height, 0) for _ in range(width)]

try:
    while True:
        clear_screen()
        screen = [[" " for _ in range(width)] for _ in range(height)]
        for x in range(width):
            y = cols[x]
            if 0 <= y < height:
                screen[y][x] = words[x % len(words)]
            cols[x] += 1
            if cols[x] >= height:
                cols[x] = random.randint(-5, 0)
        # 打印画面
        for line in screen:
            print("".join(line))
        time.sleep(0.12)
except KeyboardInterrupt:
    clear_screen()
    print("\n❤️ 心意送达 ❤️")

退出特效:按下键盘 Ctrl + C

第三种|浪漫弹窗文字(Tkinter 精美窗口,系统自带,不用pip)

适合发给对方双击直接运行,弹出告白卡片

import tkinter as tk
from tkinter import font

root = tk.Tk()
root.title("一封告白信")
root.geometry("520x320")
root.resizable(False, False)
root.configure(bg="#121226")

# 自定义字体
title_font = font.Font(family="微软雅黑", size=24, weight="bold")
text_font = font.Font(family="微软雅黑", size=14)

label1 = tk.Label(
    root,
    text="❤️ 我想对你说 ❤️",
    font=title_font,
    fg="#ff6688",
    bg="#121226"
)
label1.pack(pady=30)

msg = """
遇见你的时候
风都变得温柔

我不想只和你擦肩而过
我喜欢你,希望未来一路有你
"""
label2 = tk.Label(
    root,
    text=msg,
    font=text_font,
    fg="#eeeeee",
    bg="#121226"
)
label2.pack()

root.mainloop()

使用教程

  1. 电脑安装Python3(官网下载)
  2. 新建文本文档,粘贴代码,另存为 love.py
  3. 打开cmd,进入文件所在文件夹,输入 python love.py 运行
  4. 可以自行修改文字:把代码里的中文告白语句替换成你想说的话
posted @ 2026-07-22 22:05  code小说  阅读(2)  评论(0)    收藏  举报