程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python implements tricky spoof program to generate exe file small pop-up window blessing to good brothers, good girlfriends and roommates

編輯:Python

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文件


 

1、You can run it first to see the effect

It is recommended to set the number of cycles first  改為10次 ,Just end the process after running

 

2、先寫好代碼

"""
* @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()

3、安裝pyinstaller

pip install pyinstaller

 

2、使用pyinstaller 打包程序

2.1 進入文件路徑

2.2 開始打包

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.  就成功了

2.3 查收exe文件

When you enter the program directory, you will see another namedist目錄,打包好的exeThe program is in there

 

運行一下:

 

 

注意:如果原本的程序中使用到了相應的資源,需要復制到該目錄下,否則程序會無法運行.


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved