Nanfeng

Notes on software development, code, and curious ideas

Resolving Python and Tkinter Version Conflicts with Conda

While experimenting with Python GUI programming on macOS, my first Tkinter window rendered incorrectly:

Incorrectly rendered Tkinter window

The terminal displayed this warning:

1
DEPRECATION WARNING: The system version of Tk is deprecated and may be removed in a future release. Please don't rely on it.
Deprecated system Tk warning

Conda can isolate both a Python interpreter and its packages, which makes it useful when the system Python/Tk combination is unsuitable. Miniconda provides Conda and Python without the much larger collection bundled with Anaconda.

Download the current installer from the official Miniconda documentation and follow the instructions for your Mac’s processor architecture. After installation, restart the terminal and verify it:

1
conda --version

Create an isolated environment. Use a currently supported Python version unless a project specifically requires an older one:

1
2
3
conda create -n tkinter-demo python=3.12 tk
conda activate tkinter-demo
python -m tkinter

Leave the environment with:

1
conda deactivate

The active environment name appears in the shell prompt:

Active Conda environment

After switching away from the deprecated system Tk, the program displayed as expected:

Correct Tkinter window
+