It feels a little less fun not to give good brothers, good girlfriends, and roommates some surprises during the holidays.
目錄
1、You can run it first to see the effect
2、先寫好代碼
3、安裝pyinstaller
2、使用pyinstaller 打包程序
2.1 進入文件路徑
2.2 開始打包
2.3 查收exe文件
It is recommended to set the number of cycles first 改為10次 ,Just end the process after running
"""
* @Author: xiaofang
在校生,學習過C、Java,目前專於Python,方向:數據分析
* @Description:
Send blessings to your friends
"""
import tkinter as tk
import random
import threading
import time
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('七夕')
window.geometry("200x50" + "+" + str(a) + "+" + str(b))
tk.Label(window,
text=' 七夕快樂,not only today!', # 標簽的文字
bg='#F479EE', # 背景顏色
font=('楷體', 15), # 字體和字體大小
width=50, height=12 # 標簽長寬
).pack() # 固定窗口位置
window.mainloop()
threads = []
for i in range(200): # 需要的彈框數量
t = threading.Thread(target=dow)
threads.append(t)
time.sleep(0.1)
threads[i].start()
pip install pyinstaller
pyinstaller -F -w (-i icofile) filename
filename表示你的Python程序文件名
-w Indicates that the command line window is hidden when the program is running(不加-wThere will be black windows)
Parameters in parentheses are optional,-i icofileIndicates adding an icon to the program,圖標必須為.ico格式
icofileIndicates the location of the icon,It is recommended to put it directly in the program folder,In this way, it is good to write the file name directly when packaging
然後回車運行
We see the last line of prompts from the image above: Building EXE from EXE-00.toc completed successfully. 就成功了
When you enter the program directory, you will see another namedist目錄,打包好的exeThe program is in there
運行一下:
注意:如果原本的程序中使用到了相應的資源,需要復制到該目錄下,否則程序會無法運行.