打包个七夕exe玩玩

前段时间七夕 当别的哥们都在酒店不要不要的时候
身为程序员的我 还在单位群收到收到
正好后来看到大佬些的这个
https://www.52pojie.cn/thread-1823963-1-1.html
这个贱 我必须要犯,可是我也不能直接给他装个python吧 多麻烦 就这几个弹窗 好low 加上bgm 再打包成exe

import tkinter as tk
import random
import threading
import time
import pygame
# 音乐的路径
file=r'C:\Users\farben\Downloads\aa.flac'
# 初始化
pygame.mixer.init()
# 加载音乐文件
track = pygame.mixer.music.load(file)
# 开始播放音乐流
pygame.mixer.music.play()
 
def dow():
    window = tk.Tk()
    width=window.winfo_screenwidth()
    height=window.winfo_screenheight()
    a=random.randrange(0,width)
    b=random.randrange(0,height)
    window.title('520快乐')
    window.geometry("200x50"+"+"+str(a)+"+"+str(b))
    tk.Label(window,
        text='亲爱的嫁给我吧!',    # 标签的文字
        bg='Red',     # 背景颜色
        font=('楷体', 15),
         fg="green",         # 字体和字体大小
        width=15, height=2  # 标签长宽
        ).pack()    # 固定窗口位置
    window.mainloop()
   
threads = []
for i in range(100):#需要的弹框数量
    t = threading.Thread(target=dow)
    threads.append(t)
    time.sleep(0.1)
    threads[i].start()

好的 让我们开始打包

安装Pyinstaller
首先我们要先安装Pyinstaller,直接在cmd使用pip命令

pip install pyinstaller 

然后去你存放这个文件的目录里执行下面这行命令 qixi.ico是我从网上随便找的个图片 自行修改是打包成exe之后的一个logo

Pyinstaller -F -w -i qixi.ico word.py

执行完毕会发现当前目录多了几个文件夹,打开其中名为dist的文件夹 里面就是exe 发给女神看吧
打包个七夕exe玩玩_第1张图片

女神没电脑?,算了 那她配不上你

你可能感兴趣的:(pygame,python)