VMware ESXi and vSphere Cluster Management

Python IDLE Editor: Write, Save, Run, and Debug Programs

Learn how to use Python IDLE's Shell and editor to test code, create .py files, run modules, read tracebacks, and debug beginner programs.

What Is Python IDLE?

IDLE stands for Integrated Development and Learning Environment. It is Python's lightweight graphical environment for experimenting with Python and creating small programs.

IDLE is included with many standard Python installations. It provides an interactive Shell, a source-code editor window, and basic debugging tools. IDLE is implemented in Python and uses tkinter, Python's standard-library interface to the Tk graphical user-interface toolkit.

You can use IDLE to:

  • Test Python expressions and one-line statements interactively.
  • Write and edit reusable multi-line programs.
  • Save Python source files and run them as modules.
  • Read error messages and use basic debugging features.

IDLE is available on Windows, macOS, and Linux, although its installation package, menu location, and launch method vary. Some Python distributions do not install IDLE or its tkinter component by default.

Starting IDLE

Launch IDLE from the desktop

On Windows, open the Start menu and look for an entry under a Python version folder, such as a Python 3.x folder. On macOS or Linux, open the applications menu and search for IDLE or Python IDLE. The exact name depends on how Python was installed.

Launch IDLE from a terminal

If no desktop shortcut is available, run IDLE through a terminal using the Python interpreter:

python -m idlelib

On systems where Python 3 is named python3, use:

python3 -m idlelib

On Windows systems with the Python launcher, you can use:

py -m idlelib

These commands ask the selected Python installation to start IDLE. If the command fails, that installation may not include IDLE or tkinter.

Check the Python version

When IDLE opens, its Shell displays a startup banner containing the Python version and other information. Read this banner to confirm that IDLE is using the Python installation you intend to use. This matters when several Python versions are installed.

The IDLE Shell and Editor Window

The Shell is the interactive window used to execute Python commands immediately. Its primary prompt is three greater-than signs:

>>>

The editor window is where you create and modify Python source files. A source file normally ends with the .py extension and is called a module in normal Python terminology.

AreaBest useHow code runsWhether work is saved automatically
ShellQuick experiments, calculations, and checking individual statementsEnter code at >>> and press EnterNo; save reusable code in an editor file
Editor windowReusable multi-line programs and scriptsSave the file, then choose Run > Run ModuleNo; save changes explicitly

When a saved module runs, its printed output, status messages, and errors appear in the Shell. The editor contains the source code; the Shell displays what happens when that source code executes.

Using the Interactive Prompt

At the >>> prompt, enter an expression or one-line statement and press Enter. Python evaluates it immediately.

>>> 2 + 3
5
>>> name = "Mira"
>>> print(name)
Mira

An expression such as 2 + 3 produces a value, which the Shell displays. An assignment such as name = "Mira" stores a value in a variable and normally displays no result. A call such as print(name) writes text explicitly.

Command history

IDLE keeps a history of commands entered during the Shell session. Use the keyboard's history navigation keys, or the Shell history commands available in your IDLE version, to recall an earlier entry. Editing and reusing a previous command is useful when testing variations of an expression.

The continuation prompt

The ... prompt means that Python is waiting for the rest of an incomplete compound statement, such as an if, for, or function definition.

>>> if 3 > 1:
...     print("The condition is true")
...
The condition is true

The >>> prompt starts a new statement. The ... prompt continues the current block. In the editor, the same block is written as ordinary saved source code.

Creating a Program in the Editor

  1. Open IDLE.
  2. Choose File > New File to open an editor window.
  3. Type a complete program in the editor, not at the Shell prompt.
  4. Use indentation for statements inside blocks.
  5. Save the file before running it.

For example, enter this program:

message = "Hello from IDLE"
print(message)

For a block, indent the statements belonging to that block:

age = 12
if age >= 10:
    print("Eligible")
else:
    print("Not eligible")

Python uses indentation to define structure. The indented print statements belong to their respective branches. Use consistent spaces, commonly four spaces per level.

Editor assistance

  • Syntax highlighting uses colors for elements such as keywords, strings, comments, and names.
  • Auto-indent inserts or preserves useful indentation after a block header and when a new line is started.
  • Indentation can usually be removed when leaving a block.
  • Autocomplete, also called word completion, can suggest or complete identifiers, attributes, and keywords.

IDLE supports multiple open editor windows, so you can work with more than one source file at a time. Always check which editor window is active before saving or running.

Saving Python Source Files

Choose File > Save in the editor. For a new file, IDLE asks you to choose a folder and filename. Use the standard .py extension, such as:

hello_idle.py

Choose a meaningful filename and save it in a known project folder. The saved filename becomes the module name in normal Python terminology. For example, hello_idle.py corresponds to the module name hello_idle when imported.

Save before running a new file and save again after making changes. IDLE does not automatically preserve every edit. To work with an existing program, choose File > Open and select its .py file.

Running a Module

  1. Make sure the intended source file is active in the editor.
  2. Save the file.
  3. Choose Run > Run Module, or press F5.
  4. Read the Shell output after IDLE prepares the execution environment.

On many systems, IDLE restarts the Shell before executing the module. You may see a status line containing RESTART. This means the Shell process was restarted before the saved module ran; it is normally expected behavior, not an error.

RESTART: .../hello_idle.py
Hello from IDLE

Look at the lines after RESTART to find your program's printed output or any error report. The editor's source code is executed, while the results are shown in the Shell.

Some keyboards require Fn+F5, and system settings can assign a different action to function keys. If F5 does not work, save the file and use the menu command instead.

Common IDLE Actions

TaskMenu pathTypical shortcutExpected result
Create a new fileFile > New FileCtrl+N or Command+N, depending on platformA blank editor window opens
Open a fileFile > OpenCtrl+O or Command+O, depending on platformAn existing source file opens in an editor
Save a fileFile > SaveCtrl+S or Command+S, depending on platformThe current editor contents are written to disk
Run the current moduleRun > Run ModuleF5The saved file executes and output appears in the Shell
Start debuggingDebug > DebuggerNo universal shortcutThe debugger window opens or becomes enabled

Basic Debugging in IDLE

IDLE includes an integrated debugger intended to help beginners observe program execution. Enable it from the Debug menu, then run the program with the debugger active.

A breakpoint is a selected line where execution pauses. At a pause, you can step through the program one statement at a time and examine variables to see how their values change. This is useful when the program runs but does not produce the result you expected.

Three broad kinds of problems

  • Syntax error: Python cannot understand the source structure, often because punctuation, quotation marks, a colon, or indentation is wrong.
  • Runtime exception: The program starts but encounters an invalid operation while running, such as using a name that has not been defined.
  • Logical error: The program runs without an exception but calculates or displays the wrong result.

A traceback is Python's error report. It shows the call sequence and usually identifies the file and line where an exception occurred. Read the final error type and message, then inspect the reported line and the surrounding code.

Traceback example

Save and run this source:

print(total)

The Shell reports a NameError because total was never assigned. Use the traceback's filename and line number to locate the problem.

Common Messages and Issues

Message or symptomLikely causeResolution
RESTART displayed before outputIDLE restarted the Shell before running a moduleRead the lines after RESTART; this status is normally expected
SyntaxErrorInvalid punctuation, structure, quotation marks, or a missing colonOpen the indicated file and line; check syntax and nearby lines
NameErrorA variable or function name was used before it was defined, or its spelling differsDefine the name first and check spelling and capitalization
No .py file selected or savedThe editor file is new, unsaved, or saved with the wrong extensionChoose File > Save, use a filename ending in .py, then run it
IDLE does not openIDLE or tkinter may not be installed, or the launcher command differsTry an appropriate terminal command and check the Python installation options

Troubleshooting the IDLE Workflow

IDLE is not in the application list

Python or the IDLE component may not be installed. The application may also be listed under a version-specific Python folder, or your system may use a different launcher. Try python -m idlelib, python3 -m idlelib, or py -m idlelib as appropriate. If none works, check your Python installation or package manager for IDLE and tkinter components.

F5 does not run the program

The file may not have been saved, the editor may not be active, or the keyboard may require an Fn modifier. Save the file, click in the editor, and choose Run > Run Module from the menu.

The output is missing or unexpected

Confirm the active filename, save the latest changes, and run the module again. Check whether the program contains a print() call and whether a condition selected a different branch. Temporary print calls or the debugger can help inspect values.

SyntaxError or IndentationError appears

Go to the file and line named in the report. Check for a missing colon after a compound statement, unmatched parentheses or quotation marks, and inconsistent indentation. Use consistent spaces for each indentation level.

When IDLE Is a Good Choice

IDLE is a suitable learning environment and a practical choice for small scripts. It lets beginners move directly from an interactive experiment to a saved program without learning a complex project system first.

As projects grow, a more feature-rich editor or IDE may provide stronger project navigation, automated testing, version-control integration, virtual-environment management, refactoring, and code analysis. Those tools are options, not prerequisites. Mastering the basic IDLE workflow—experiment, edit, save, run, read errors, and debug—builds skills that transfer to other Python tools.

Quick Practice Workflow

  1. Open IDLE and verify the Python version in the Shell banner.
  2. At >>>, enter 2 + 3 and confirm that Python displays 5.
  3. Choose File > New File.
  4. Enter message = "Hello from IDLE" and print(message).
  5. Save the file as hello_idle.py in a known folder.
  6. Choose Run > Run Module or press F5.
  7. Find the output after the Shell's RESTART status line.
  8. Introduce a small error, run the file, and use the traceback to locate it.

For a concise reference to this workflow, see the Python IDLE editor guide.