-

26.5. IDLE

+

IDLE

Source code: Lib/idlelib/


IDLE is Python’s Integrated Development and Learning Environment.

IDLE has the following features:

  • coded in 100% pure Python, using the tkinter GUI toolkit
  • -
  • cross-platform: works mostly the same on Windows, Unix, and Mac OS X
  • +
  • cross-platform: works mostly the same on Windows, Unix, and macOS
  • Python shell window (interactive interpreter) with colorizing of code input, output, and error messages
  • multi-window text editor with multiple undo, Python colorizing, @@ -107,16 +120,19 @@
  • configuration, browsers, and other dialogs
-

26.5.2. Editing and navigation

+

Editing and navigation

+
+

Editor windows

+

IDLE may open editor windows when it starts, depending on settings +and how you start IDLE. Thereafter, use the File menu. There can be only +one open editor window for a given file.

+

The title bar contains the name of the file, the full path, and the version +of Python and IDLE running the window. The status bar contains the line +number (‘Ln’) and column number (‘Col’). Line numbers start with 1; +column numbers with 0.

+

IDLE assumes that files with a known .py* extension contain Python code +and that other files do not. Run Python code with the Run menu.

+
+
+

Key bindings

In this section, ‘C’ refers to the Control key on Windows and Unix and -the Command key on Mac OSX.

+the Command key on macOS.

  • Backspace deletes to the left; Del deletes to the right

  • @@ -395,8 +433,9 @@

Standard keybindings (like C-c to copy and C-v to paste) may work. Keybindings are selected in the Configure IDLE dialog.

+
-

26.5.2.1. Automatic indentation

+

Automatic indentation

After a block-opening statement, the next line is indented by 4 spaces (in the Python Shell window by one tab). After certain keywords (break, return etc.) the next line is dedented. In leading indentation, Backspace deletes up @@ -406,7 +445,7 @@

See also the indent/dedent region commands in the edit menu.

-

26.5.2.2. Completions

+

Completions

Completions are supplied for functions, classes, and attributes of classes, both built-in and user-defined. Completions are also provided for filenames.

@@ -441,7 +480,7 @@ longer or disable the extension.

-

26.5.2.3. Calltips

+

Calltips

A calltip is shown when one types ( after the name of an accessible function. A name expression may include dots and subscripts. A calltip remains until it is clicked, the cursor is moved out of the argument area, @@ -464,7 +503,15 @@ or immediately run an existing file before editing.

-

26.5.2.4. Python Shell window

+

Python Shell window

+

With IDLE’s Shell, one enters, edits, and recalls complete statements. +Most consoles and terminals only work with a single physical line at a time.

+

When one pastes code into Shell, it is not compiled and possibly executed +until one hits Return. One may edit pasted code first. +If one pastes more that one statement into Shell, the result will be a +SyntaxError when multiple statements are compiled as if they were one.

+

The editing features described in previous subsections work when entering +code interactively. IDLE’s Shell window also responds to the following keys.

  • C-c interrupts executing command

  • @@ -474,15 +521,15 @@

    Command history

    • Alt-p retrieves previous command matching what you have typed. On -OS X use C-p.
    • -
    • Alt-n retrieves next. On OS X use C-n.
    • +macOS use C-p. +
    • Alt-n retrieves next. On macOS use C-n.
    • Return while on any previous command retrieves that command
-

26.5.2.5. Text colors

+

Text colors

Idle defaults to black on white text, but colors text with special meanings. For the shell, these are shell output, shell error, user output, and user error. For Python code, at the shell prompt or in an editor, these are @@ -496,7 +543,7 @@

-

26.5.3. Startup and code execution

+

Startup and code execution

Upon startup with the -s option, IDLE will execute the file referenced by the environment variables IDLESTARTUP or PYTHONSTARTUP. IDLE first checks for IDLESTARTUP; if IDLESTARTUP is present the file @@ -510,7 +557,7 @@ executed in the Tk namespace, so this file is not useful for importing functions to be used from IDLE’s Python shell.

-

26.5.3.1. Command line usage

+

Command line usage

idle.py [-c command] [-d] [-e] [-h] [-i] [-r file] [-s] [-t title] [-] [arg] ...
 
 -c command  run command in the shell window
@@ -535,7 +582,7 @@
 
 
-

26.5.3.2. Startup failure

+

Startup failure

IDLE uses a socket to communicate between the IDLE GUI process and the user code execution process. A connection must be established whenever the Shell starts or restarts. (The latter is indicated by a divider line that says @@ -570,26 +617,75 @@

If IDLE quits with no message, and it was not started from a console, try starting from a console (python -m idlelib) and see if a message appears.

-
-

26.5.3.3. IDLE-console differences

+
+

Running user code

With rare exceptions, the result of executing Python code with IDLE is -intended to be the same as executing the same code in a console window. +intended to be the same as executing the same code by the default method, +directly with Python in a text-mode system console or terminal window. However, the different interface and operation occasionally affect -visible results. For instance, sys.modules starts with more entries.

-

IDLE also replaces sys.stdin, sys.stdout, and sys.stderr with -objects that get input from and send output to the Shell window. -When Shell has the focus, it controls the keyboard and screen. This is +visible results. For instance, sys.modules starts with more entries, +and threading.activeCount() returns 2 instead of 1.

+

By default, IDLE runs user code in a separate OS process rather than in +the user interface process that runs the shell and editor. In the execution +process, it replaces sys.stdin, sys.stdout, and sys.stderr +with objects that get input from and send output to the Shell window. +The original values stored in sys.__stdin__, sys.__stdout__, and +sys.__stderr__ are not touched, but may be None.

+

When Shell has the focus, it controls the keyboard and screen. This is normally transparent, but functions that directly access the keyboard -and screen will not work. If sys is reset with importlib.reload(sys), -IDLE’s changes are lost and things like input, raw_input, and -print will not work correctly.

-

With IDLE’s Shell, one enters, edits, and recalls complete statements. -Some consoles only work with a single physical line at a time. IDLE uses -exec to run each statement. As a result, '__builtins__' is always -defined for each statement.

+and screen will not work. These include system-specific functions that +determine whether a key has been pressed and if so, which.

+

IDLE’s standard stream replacements are not inherited by subprocesses +created in the execution process, whether directly by user code or by modules +such as multiprocessing. If such subprocess use input from sys.stdin +or print or write to sys.stdout or sys.stderr, +IDLE should be started in a command line window. The secondary subprocess +will then be attached to that window for input and output.

+

If sys is reset by user code, such as with importlib.reload(sys), +IDLE’s changes are lost and input from the keyboard and output to the screen +will not work correctly.

+
+
+

User output in Shell

+

When a program outputs text, the result is determined by the +corresponding output device. When IDLE executes user code, sys.stdout +and sys.stderr are connected to the display area of IDLE’s Shell. Some of +its features are inherited from the underlying Tk Text widget. Others +are programmed additions. Where it matters, Shell is designed for development +rather than production runs.

+

For instance, Shell never throws away output. A program that sends unlimited +output to Shell will eventually fill memory, resulting in a memory error. +In contrast, some system text windows only keep the last n lines of output. +A Windows console, for instance, keeps a user-settable 1 to 9999 lines, +with 300 the default.

+

Text widgets display a subset of Unicode, the Basic Multilingual Plane (BMP). +Which characters get a proper glyph instead of a replacement box depends on +the operating system and installed fonts. Newline characters cause following +text to appear on a new line, but other control characters are either +replaced with a box or deleted. However, repr(), which is used for +interactive echo of expression values, replaces control characters, +some BMP codepoints, and all non-BMP characters with escape codes +before they are output.

+

Normal and error output are generally kept separate (on separate lines) +from code input and each other. They each get different highlight colors.

+

For SyntaxError tracebacks, the normal ‘^’ marking where the error was +detected is replaced by coloring the text with an error highlight. +When code run from a file causes other exceptions, one may right click +on a traceback line to jump to the corresponding line in an IDLE editor. +The file will be opened if necessary.

+

Shell has a special facility for squeezing output lines down to a +‘Squeezed text’ label. This is done automatically +for output over N lines (N = 50 by default). +N can be changed in the PyShell section of the General +page of the Settings dialog. Output with fewer lines can be squeezed by +right clicking on the output. This can be useful lines long enough to slow +down scrolling.

+

Squeezed output is expanded in place by double-clicking the label. +It can also be sent to the clipboard or a separate view window by +right-clicking the label.

-

26.5.3.4. Developing tkinter applications

+

Developing tkinter applications

IDLE is intentionally different from standard Python in order to facilitate development of tkinter programs. Enter import tkinter as tk; root = tk.Tk() in standard Python and nothing appears. Enter the same @@ -609,7 +705,7 @@ re-enable the mainloop call when running in standard Python.

-

26.5.3.5. Running without a subprocess

+

Running without a subprocess

By default, IDLE executes user code in a separate subprocess via a socket, which uses the internal loopback interface. This connection is not externally visible and no data is sent to or received from the Internet. @@ -635,24 +731,39 @@

-

26.5.4. Help and preferences

-
-

26.5.4.1. Additional help sources

-

IDLE includes a help menu entry called “Python Docs” that will open the -extensive sources of help, including tutorials, available at docs.python.org. -Selected URLs can be added or removed from the help menu at any time using the -Configure IDLE dialog. See the IDLE help option in the help menu of IDLE for -more information.

+

Help and preferences

+
+

Help sources

+

Help menu entry “IDLE Help” displays a formatted html version of the +IDLE chapter of the Library Reference. The result, in a read-only +tkinter text window, is close to what one sees in a web browser. +Navigate through the text with a mousewheel, +the scrollbar, or up and down arrow keys held down. +Or click the TOC (Table of Contents) button and select a section +header in the opened box.

+

Help menu entry “Python Docs” opens the extensive sources of help, +including tutorials, available at docs.python.org/x.y, where ‘x.y’ +is the currently running Python version. If your system +has an off-line copy of the docs (this may be an installation option), +that will be opened instead.

+

Selected URLs can be added or removed from the help menu at any time using the +General tab of the Configure IDLE dialog .

-

26.5.4.2. Setting preferences

+

Setting preferences

The font preferences, highlighting, keys, and general preferences can be changed via Configure IDLE on the Option menu. Keys can be user defined; IDLE ships with four built-in key sets. In addition, a user can create a custom key set in the Configure IDLE dialog under the keys tab.

+
+

IDLE on macOS

+

Under System Preferences: Dock, one can set “Prefer tabs when opening +documents” to “Always”. This setting is not compatible with the tk/tkinter +GUI framework used by IDLE, and it breaks a few IDLE features.

+
-

26.5.4.3. Extensions

+

Extensions

IDLE contains an extension facility. Preferences for extensions can be changed with the Extensions tab of the preferences dialog. See the beginning of config-extensions.def in the idlelib directory for further @@ -668,42 +779,46 @@