Fun Python Prank Scripts and How to Package Them as Executables
This article showcases several playful Python prank programs, explains how to bundle them into standalone EXE files with PyInstaller, provides the full source code for each script, warns about potential issues, and promotes a free Python learning resource via QR code.
Python can be used for many boring yet entertaining tasks, and this article presents several prank programs along with instructions on how to package them into executable files using pip install pyinstaller and the command pyinstaller -F filename.py .
Prank program one: an infinite loop that asks the user to guess what the author is thinking and always prints "Wrong guess".
<code>while True:
n = input("猜猜我在想啥?")
print("猜错喽")
</code>Prank program two: a relentless error dialog using tkinter.messagebox that repeatedly shows a Windows error message.
<code>import tkinter.messagebox
while True:
tkinter.messagebox.showerror('Windows 错误','你的电脑正在被攻击!')
</code>Prank program three: an infinite loop that opens the CSDN website in the default browser, which can cause the computer to become unresponsive.
<code>import webbrowser
while True:
webbrowser.open('www.csdn.net')
</code>Prank program four: a multithreaded Tkinter application that randomly creates pop‑up windows across the screen, each displaying a humorous message.
<code>import tkinter as tk
import random, threading, 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()
</code>Prank program five: a script that prints an ASCII art banner, asks the user to choose an option, and if the wrong option is selected, triggers a system shutdown after a short delay.
<code>import os, time
a = """...ASCII art..."""
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)
</code>The article warns readers not to run the scripts without understanding the consequences and includes a QR code that offers a free Python course with extensive learning materials.
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.