A tiny, cross-platform Tkinter app for quickly writing, running, compiling, and inspecting Python code. Ideal for quick experiments, teaching demos, or peeking at CPython bytecode without leaving a GUI.
- Editor with auto-indent (adds 4 spaces after lines ending with
:
). - Run code in a sandboxed temp file (10-second timeout) and view stdout/stderr.
- Compile to
.pyc
with clear compile errors. - Show Bytecode using
dis
for the current buffer. - Open / Save
.py
files. - Clear Output button to reset the console panel.
-
Python 3.8+ (works on 3.x).
-
Tkinter (bundled with most Python builds).
- macOS (Homebrew Python):
brew install python-tk@3.12
(or matching version). - Ubuntu/Debian:
sudo apt-get install python3-tk
. - Fedora:
sudo dnf install python3-tkinter
.
- macOS (Homebrew Python):
-
No third-party packages required (uses stdlib:
tkinter
,subprocess
,py_compile
,dis
, etc.).
-
Save the script as
py_compiler_gui.py
. -
(Optional) Make it executable on macOS/Linux:
chmod +x py_compiler_gui.py
-
Run:
# Using the current Python python3 py_compiler_gui.py # Or with the shebang on Unix ./py_compiler_gui.py
On Windows, double-clicking may work if
.py
is associated with Python; otherwise run fromcmd
/PowerShell.
-
Editor: Type or paste Python code. Auto-indent triggers when you press Enter after a line ending with
:
. -
File → Open / Save: Load or save
.py
files. The current file path is remembered for subsequent saves. -
Run:
- Executes the current buffer by writing it to a temporary
.py
and invokingsys.executable
. - Output and errors appear in the Output panel.
- Execution is terminated after 10 seconds (to prevent runaway scripts).
- Executes the current buffer by writing it to a temporary
-
Compile:
- Compiles the buffer to
.pyc
viapy_compile.compile()
and reports the.pyc
path or compile errors.
- Compiles the buffer to
-
Show Bytecode:
- Compiles the buffer to a code object and disassembles it via
dis.dis(...)
into the Output panel.
- Compiles the buffer to a code object and disassembles it via
-
Clear Output: Wipes the Output panel.
- Enter: Auto-indent continues current line’s leading whitespace; adds four spaces if the line ends with
:
. - Undo/Redo: The editor widget supports undo/redo (Ctrl/Cmd+Z / Ctrl/Cmd+Y).
- Scrolling: Both editor and output are scrollable.
- Never run untrusted code. The app does not sandbox OS access or imports.
- The 10-second timeout applies only to the Run action (not to compilation or bytecode view).
- Temporary files are created during run/compile steps; the OS typically cleans them up.
-
ModuleNotFoundError: No module named 'tkinter'
- Install the Tk bindings for your OS (see Requirements).
-
_tkinter.TclError: no display name and no $DISPLAY environment variable
(Linux/WSL)- You’re in a headless environment. Run under a desktop session or use X11 forwarding.
-
Nothing happens on Run
- Check the Output panel for exceptions.
- Scripts waiting for input() will hang until timeout (no interactive stdin).
-
Permissions on macOS
- If Gatekeeper blocks execution, run from Terminal or allow in System Settings → Privacy & Security.
Create a single-file executable using PyInstaller:
pip install pyinstaller
pyinstaller --noconsole --onefile --name PythonTestCompiler py_compiler_gui.py
The binary will appear in the dist/
folder. On macOS, you may need to sign/notarize for distribution.
- Line numbers and basic syntax highlighting.
- Find/Replace, Go-to-line.
- Configurable run timeout.
- Basic REPL input support.
- Bytecode diff (before/after small edits).
Issues and PRs welcome! Keep dependencies stdlib-only where possible, and test on Windows, macOS, and Linux with Python 3.8–3.12.
MIT (or your preferred license). Add a LICENSE
file at the repo root.
.
├── py_compiler_gui.py # The GUI application (this file)
├── README.md # You are here
└── LICENSE # MIT or similar
- The app uses
sys.executable
to ensure it runs the buffer with the same Python that launched the GUI. dis.dis()
is directed at the output text widget via its file-like interface.- Auto-indent uses a simple regex for leading whitespace and a
:
suffix check—easy to extend for other cases.