💌 Python 表白神器:一行命令,满屏爱心 + 打字机情话

💻 源码:love.py(30 行)

python 复制代码
import os, time, random, sys

def heart_screen():
    rows, cols = os.get_terminal_size()
    heart = "💖"
    while True:
        print("".join(random.choices([heart, " "], weights=[1, 3]) * cols))
        time.sleep(0.08)

def type_writer(text):
    for ch in text:
        sys.stdout.write(ch)
        sys.stdout.flush()
        time.sleep(0.08)

def main():
    # 1. 满屏爱心雨(后台线程)
    import threading
    t = threading.Thread(target=heart_screen, daemon=True)
    t.start()

    # 2. 打字机情话
    time.sleep(2)  # 让爱心飞一会
    msg = "我想把全世界的温柔都给你,也包括我自己。❤️"
    type_writer(msg)

    # 3. 彩蛋:等待回应
    input("\n\n👉 你愿意吗?(按 Enter 接受💕)")

if __name__ == "__main__":
    main()

🚀 运行方式

bash 复制代码
python love.py

支持 Windows / macOS / Linux 终端

Ctrl+C 随时退出


🌈 可自定义玩法

python 复制代码
# 换爱心颜色
heart = "\033[35m💖\033[0m"  # 紫色

# 换文字
msg = "余生请多指教,我的小太阳🌞"

# 换速度
time.sleep(0.05)  # 更快打字

📦 彩蛋进阶(可选)

  1. 语音朗读(需安装库)
bash 复制代码
pip install pyttsx3
python 复制代码
import pyttsx3
engine = pyttsx3.init()
engine.say(msg); engine.runAndWait()
  1. 打包成 exe
bash 复制代码
pip install pyinstaller
pyinstaller -F love.py
# dist/love.exe 直接发给 TA!
相关推荐
MetaLite15 分钟前
SpringBoot整合FastJson2数据脱敏-接口日志与失败降级
java·spring boot·后端
xixingzhe215 分钟前
SpringBoot 接口缓存实现
spring boot·后端·缓存
名字还没想好☜26 分钟前
Go 时间格式化为什么用 2006-01-02:time.Format/Parse 的参考时间、时区与解析踩坑
开发语言·后端·golang·go
jyOverQ4 小时前
RabbitMQ 消息积压怎么办?Prefetch、消费者并发与扩容
分布式·后端·rabbitmq
东风破_11 小时前
从跨域到 WebSocket:前端跨域方案、SSE 与双向实时通信详解
前端·后端
行百里er12 小时前
Gateway 上别硬塞 MVC:DeferredImportSelector 看菜下锅
spring boot·后端·开源
名字还没想好☜12 小时前
Java 遍历时删元素抛 ConcurrentModificationException:fail-fast 原理与三种正确删法
后端
IT_陈寒13 小时前
React Hooks闭包陷阱差点让我加班到凌晨
前端·人工智能·后端
码事漫谈14 小时前
本体论,彻底懂
后端
创新技术阁14 小时前
FastapiAdmin 系统日志体系与核心配置参数详解
前端·后端·fastapi