A minimal Tkinter desktop app that displays a random programming joke when you click a button. The implementation is intentionally small (single file) to make it easy to run, review, and extend.
- Type: Desktop GUI
- Language: Python
- UI: Tkinter
- Jokes:
pyjokes - Entry point:
pythonjokegenerator.py
- One-window GUI titled “Python Joke Generator”
- Starter prompt text
- Generate Joke button fetches a random joke via
pyjokes.get_joke()
.
├── pythonjokegenerator.py
└── README.md
- Python 3 (any modern Python 3.x should work)
- Tkinter
- Usually included with Python on Windows/macOS
- Some Linux distros require installing it separately
- Python package:
pyjokes
Windows (PowerShell):
python -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install --upgrade pipWindows (cmd.exe):
python -m venv .venv
.venv\Scripts\activate.bat
python -m pip install --upgrade pipmacOS/Linux:
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pippython -m pip install pyjokespython pythonjokegenerator.py- The Tkinter window is created and configured (
title,geometry). - Clicking Generate Joke calls
generate_joke(). generate_joke()callspyjokes.get_joke()and updates the label withjoke_label.config(text=...).
This is a straightforward event-driven flow: Tkinter’s mainloop() waits for UI events and invokes the bound callback.
-
ModuleNotFoundError: No module named 'pyjokes'- Install it into the same environment you’re running:
python -m pip install pyjokes. - If you’re using a venv, make sure it’s activated before installing/running.
- Install it into the same environment you’re running:
-
Tkinter import fails on Linux
- Debian/Ubuntu:
sudo apt-get install python3-tk
- Debian/Ubuntu:
-
Multiple Python installs on Windows
- Prefer
python -m pip ...to ensure pip targets the same interpreter.
- Prefer
- Wrap the UI into an
Appclass to avoid module-level widget variables. - Add a Copy to clipboard button.
- Add joke selection controls (category/language) if you choose to expose
pyjokesoptions.