Five Boring Python Prank Programs and How to Package Them as Executables
This article presents five simple yet mischievous Python scripts—ranging from endless guessing loops to intrusive pop‑ups and automatic browser launches—explains how to bundle them into standalone executables with PyInstaller, and warns about potential system issues.
Python can be used for many amusing, albeit pointless, tricks; this article shares five such prank programs and shows how to package them into a single executable for sharing with friends.
First, install PyInstaller with pip install pyinstaller and use the command pyinstaller -F filename.py to create an .exe file. If errors occur, solutions are provided at the end.
Prank Program One
A never‑ending loop that asks the user to guess what the author is thinking and always replies that the guess is wrong.
while True:
n = input("猜猜我在想啥?")
print("猜错喽")The friend will never know the answer.
Prank Program Two
An infinite loop that repeatedly shows an error message box claiming the computer is under attack.
import tkinter.messagebox
while True:
tkinter.messagebox.showerror('Windows 错误', '你的电脑正在被攻击!')Running this can be very irritating, especially if the victim cannot easily kill the process.
Prank Program Three
This script continuously opens the CSDN website in the default browser, quickly exhausting system resources.
import webbrowser
while True:
webbrowser.open('www.csdn.net')After a short time the computer may freeze due to high CPU usage.
Prank Program Four
A more dynamic prank that creates random pop‑up windows at random screen positions using tkinter , random , threading , and time . The windows display a humorous message.
import tkinter as tk
import random
import threading
import time
def boom():
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='你是一个傻狍子', bg='green',
font=('宋体', 17), width=20, height=4).pack()
window.mainloop()
threads = []
for i in range(100):
t = threading.Thread(target=boom)
threads.append(t)
time.sleep(0.1)
threads[i].start()The effect is shown in the accompanying screenshot and can be customized.
Prank Program Five
This script displays an ASCII art banner, then offers a menu; choosing option 1 pretends to schedule a purchase, while any other choice triggers a system shutdown after a short delay.
import os
import time
a = """
oooo oooooooooo. .oooooo..o oooo o8o oooo oooo
`888 `888' `Y8b d8P' `Y8 `888 `"' `888 `888
888 888 888 Y88bo. .ooooo. .ooooo. 888 oooo ooo 888 888
888 888 888 `"Y8888o. d88' `88b d88' `"Y8 888 .8P' `88. 888 888
888 888 888 8888888 `"Y88b 888ooo888 888 888888. 888 888 888
888 888 d88' .d8P 888 .o 888 .o 888 `88b. 888 888 888
.o. 88P o888bood8P' 8""88888P' `Y8bod8P' `Y8bod8P' o888o o888o o888o o888o
`Y888P
功能列表:
1.预约商品
2.秒杀抢购商品
"""
print(a)
key = input("请选择:")
if key == "1":
time.sleep(1.5)
print('没有预约到\n')
time.sleep(3)
print('没事的,来抱一哈\n')
else:
print("既然如此...")
time.sleep(3)
print("那你想得美~~~~~")
os.system('shutdown -r -t 10')
time.sleep(10)Do not run this script unless you are prepared for the shutdown.
These examples demonstrate how simple Python code can be turned into playful (or disruptive) executables, but they also highlight the importance of using such tools responsibly.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.