Tkinter Designer

← tkinter how-to

Why is tkinter not working in VS Code?

In most cases tkinter is installed correctly and VS Code is simply running a different Python from the one you tested. Check which interpreter it has selected before changing anything else.

# In VS Code:  Ctrl+Shift+P  ->  "Python: Select Interpreter"
# Then confirm from the same terminal VS Code is using:
python -c "import sys, tkinter; print(sys.executable)"

The interpreter is the usual answer

VS Code remembers an interpreter per workspace, and it is easy to end up on a venv, a Conda environment or a Microsoft Store Python that has no Tk support while your system Python has plenty. The path printed above is the one that matters — if it is not what you expected, select the right one and reload the window.

A red squiggle is not the same as an error

Pylance reporting Import "tkinter" could not be resolved is a static analysis message from the language server, not something your program hit. If the script runs, the import is fine and Pylance is looking at a different environment — the same fix, selecting the interpreter, clears it.

The reverse is also worth knowing: no squiggle but a ModuleNotFoundError at runtime means the editor and the runtime disagree, which again points at the interpreter rather than at tkinter.

Extensions that run their own Python

The Code Runner extension executes a command it stores separately, so it can ignore the interpreter you picked. If the Run button fails but running from the terminal works, that is the cause — either point Code Runner at the same interpreter or use the built-in run.

Remote, WSL and SSH sessions

Tkinter needs a display. Over Remote-SSH or in a container there is usually none, so the import succeeds and the window never appears, or Tk raises an error about not connecting to a display. Modern WSL has WSLg and works; older setups need an X server on Windows and DISPLAY set. Running the script locally is the quickest way to tell whether this is your problem.

Doing it without the lookup

Designing does not depend on any of this: the canvas is a web page, so the interpreter question only arrives when you run the code you downloaded — by which point you know which Python you are pointing at.

Lay the window out visually and read the generated Python as you go.

Open the tkinter designer →

Related questions