Fundamentals 6 min read

Turn Simple Python Scripts into Prank Executables with PyInstaller

This guide shows how to create a series of playful Python prank programs, package them into standalone EXE files using PyInstaller, troubleshoot a common encoding bug, and includes ready-to-use code snippets and visual examples for each trick.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Turn Simple Python Scripts into Prank Executables with PyInstaller

Python can be used for many amusing tricks; this article presents several "boring but interesting" prank programs and explains 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. If encoding errors occur, modify the offending line from out = out.decode(encoding) to out = out and rebuild.

Prank Program #1

A loop that asks the user to guess what you are thinking and always replies "wrong".

while True:
  n = input("Guess what I'm thinking?")
  print("Wrong guess")

The victim never learns your thought.

Prank Program #2

A relentless error dialog that repeatedly shows a fake Windows error.

import tkinter.messagebox
while True:
    tkinter.messagebox.showerror('Windows Error','Your computer is under attack!')

It’s especially irritating if the target cannot terminate the process.

Prank Program #3

An infinite loop that opens the CSDN website in the default browser, quickly overwhelming the system.

import webbrowser
while True:
    webbrowser.open('www.csdn.net')

Running this may cause the computer to freeze.

Prank Program #4

A multithreaded GUI that randomly spawns pop‑up windows across the screen.

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('You are a silly deer')
    window.geometry('200x50+'+str(a)+'+'+str(b))
    tk.Label(window, text='You are a silly deer', bg='green', font=('SimSun',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 GIF.

Prank Program #5

A script that pretends to offer product reservation and flash‑sale options, but ultimately shuts down the computer.

import os, time
a = """... (ASCII art omitted) ..."""
print(a)
key = input("Choose:")
if key == "1":
    time.sleep(1.5)
    print('No reservation')
    time.sleep(3)
    print('It’s okay, come hug')
else:
    print('Since you said so...')
    time.sleep(3)
    print('Dream on')
    os.system('shutdown -r -t 10')
time.sleep(10)

Do not run this unless you want to reboot the machine.

PyInstaller Encoding Bug Fix

When packaging with PyInstaller, an error may appear:

AttributeError: 'str' object has no attribute 'decode'

Fix it by changing the line out = out.decode(encoding) to out = out in the PyInstaller source, then rebuild; the EXE will be generated in the dist folder.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PythonExecutablePrank Scripts
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.