- -
-

IDLE

-

Source code: Lib/idlelib/

-
+
+

IDLE — Python editor and shell

+

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 macOS

  • Python shell window (interactive interpreter) with colorizing of code input, output, and error messages

  • @@ -118,8 +16,14 @@

    Navigation

    of global and local namespaces

  • configuration, browsers, and other dialogs

- -
-

Format menu (Editor window only)

+
+
+

Format menu (Editor window only)

+
Format Paragraph

Rewrap the text block containing the text insert cursor. +Avoid code lines. See Format block in the +Editing and Navigation section below.

+
Indent Region

Shift selected lines right by the indent width (default 4 spaces).

Dedent Region

Shift selected lines left by the indent width (default 4 spaces).

@@ -236,19 +149,15 @@

Edit menu (Shell and Editor)str.rstrip() to each line, including lines within multiline strings. Except for Shell windows, remove extra newlines at the end of the file.

-
-
-

Run menu (Editor window only)

+ +
+

Run menu (Editor window only)

Run Module

Do Check Module. If no error, restart the shell to clean the environment, then execute the module. Output is displayed in the Shell @@ -277,13 +186,13 @@

Edit menu (Shell and Editor) -

Shell menu (Shell window only)

+

+
+

Shell menu (Shell window only)

View Last Restart

Scroll the shell window to the last Shell restart.

-
Restart Shell

Restart the shell to clean the environment.

+
Restart Shell

Restart the shell to clean the environment and reset display and exception handling.

Previous History

Cycle through earlier commands in history which match the current entry.

@@ -292,9 +201,9 @@

Shell menu (Shell window only) -

Debug menu (Shell window only)

+

+
+

Debug menu (Shell window only)

Go to File/Line

Look on the current line. with the cursor, and the line above for a filename and line number. If found, open the file if not already open, and show the @@ -314,9 +223,9 @@

Debug menu (Shell window only) -

Options menu (Shell and Editor)

+

+
+

Options menu (Shell and Editor)

Configure IDLE

Open a configuration dialog and change preferences for the following: fonts, indentation, keybindings, text color themes, startup windows and @@ -346,14 +255,14 @@

Options menu (Shell and Editor) -

Window menu (Shell and Editor)

+

+
+

Window menu (Shell and Editor)

Lists the names of all open windows; select one to bring it to the foreground (deiconifying it if necessary).

-
-
-

Help menu (Shell and Editor)

+ +
+

Help menu (Shell and Editor)

About IDLE

Display version, copyright, license, credits, and more.

@@ -369,9 +278,9 @@

Help menu (Shell and Editor)Help sources subsection below for more on Help menu choices.

-

-
-

Context Menus

+ +
+

Context menus

Open a context menu by right-clicking in a window (Control-click on macOS). Context menus have the standard clipboard functions also on the Edit menu.

@@ -404,12 +313,12 @@

Help menu (Shell and Editor) -

Editing and navigation

-
-

Editor windows

+

+ +
+

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.

@@ -419,41 +328,35 @@

Editor windows -

Key bindings

-

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

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

  • -
  • C-Backspace delete word left; C-Del delete word to the right

  • -
  • Arrow keys and Page Up/Page Down to move around

  • -
  • C-LeftArrow and C-RightArrow moves by words

  • -
  • Home/End go to begin/end of line

  • -
  • C-Home/C-End go to begin/end of file

  • -
  • Some useful Emacs bindings are inherited from Tcl/Tk:

    -
    -
      -
    • C-a beginning of line

    • -
    • C-e end of line

    • -
    • C-k kill line (but doesn’t put it in clipboard)

    • -
    • C-l center window around the insertion point

    • -
    • C-b go backward one character without deleting (usually you can -also use the cursor key for this)

    • -
    • C-f go forward one character without deleting (usually you can -also use the cursor key for this)

    • -
    • C-p go up one line (usually you can also use the cursor key for -this)

    • -
    • C-d delete next character

    • -
    -
    -
  • +

+
+

Key bindings

+

The IDLE insertion cursor is a thin vertical bar between character +positions. When characters are entered, the insertion cursor and +everything to its right moves right one character and +the new character is entered in the new space.

+

Several non-character keys move the cursor and possibly +delete characters. Deletion does not puts text on the clipboard, +but IDLE has an undo list. Wherever this doc discusses keys, +‘C’ refers to the Control key on Windows and +Unix and the Command key on macOS. (And all such discussions +assume that the keys have not been re-bound to something else.)

+
    +
  • Arrow keys move the cursor one character or line.

  • +
  • C-LeftArrow and C-RightArrow moves left or right one word.

  • +
  • Home and End go to the beginning or end of the line.

  • +
  • Page Up and Page Down go up or down one screen.

  • +
  • C-Home and C-End go to beginning or end of the file.

  • +
  • Backspace and Del (or C-d) delete the previous +or next character.

  • +
  • C-Backspace and C-Del delete one word left or right.

  • +
  • C-k deletes (‘kills’) everything to the right.

-

Standard keybindings (like C-c to copy and C-v to paste) +

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

-
-
-

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 @@ -462,67 +365,97 @@

Automatic indentation

See also the indent/dedent region commands on the Format menu.

-

-
-

Completions

-

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

-

The AutoCompleteWindow (ACW) will open after a predefined delay (default is -two seconds) after a ‘.’ or (in a string) an os.sep is typed. If after one -of those characters (plus zero or more other characters) a tab is typed -the ACW will open immediately if a possible continuation is found.

-

If there is only one possible completion for the characters entered, a -Tab will supply that completion without opening the ACW.

-

‘Show Completions’ will force open a completions window, by default the -C-space will open a completions window. In an empty -string, this will contain the files in the current directory. On a -blank line, it will contain the built-in and user-defined functions and -classes in the current namespaces, plus any modules imported. If some -characters have been entered, the ACW will attempt to be more specific.

-

If a string of characters is typed, the ACW selection will jump to the -entry most closely matching those characters. Entering a tab will -cause the longest non-ambiguous match to be entered in the Editor window or -Shell. Two tab in a row will supply the current ACW selection, as -will return or a double click. Cursor keys, Page Up/Down, mouse selection, -and the scroll wheel all operate on the ACW.

-

“Hidden” attributes can be accessed by typing the beginning of hidden -name after a ‘.’, e.g. ‘_’. This allows access to modules with -__all__ set, or to class-private attributes.

-

Completions and the ‘Expand Word’ facility can save a lot of typing!

-

Completions are currently limited to those in the namespaces. Names in -an Editor window which are not via __main__ and sys.modules will -not be found. Run the module once with your imports to correct this situation. -Note that IDLE itself places quite a few modules in sys.modules, so -much can be found by default, e.g. the re module.

-

If you don’t like the ACW popping up unbidden, simply make the delay -longer or disable the extension.

-
-
-

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, -or ) is typed. When the cursor is in the argument part of a definition, -the menu or shortcut display a calltip.

-

A calltip consists of the function signature and the first line of the -docstring. For builtins without an accessible signature, the calltip -consists of all lines up the fifth line or the first blank line. These -details may change.

-

The set of accessible functions depends on what modules have been imported -into the user process, including those imported by Idle itself, -and what definitions have been run, all since the last restart.

+ +
+

Search and Replace

+

Any selection becomes a search target. However, only selections within +a line work because searches are only performed within lines with the +terminal newline removed. If [x] Regular expression is checked, the +target is interpreted according to the Python re module.

+
+
+

Completions

+

Completions are supplied, when requested and available, for module +names, attributes of classes or functions, or filenames. Each request +method displays a completion box with existing names. (See tab +completions below for an exception.) For any box, change the name +being completed and the item highlighted in the box by +typing and deleting characters; by hitting Up, Down, +PageUp, PageDown, Home, and End keys; +and by a single click within the box. Close the box with Escape, +Enter, and double Tab keys or clicks outside the box. +A double click within the box selects and closes.

+

One way to open a box is to type a key character and wait for a +predefined interval. This defaults to 2 seconds; customize it +in the settings dialog. (To prevent auto popups, set the delay to a +large number of milliseconds, such as 100000000.) For imported module +names or class or function attributes, type ‘.’. +For filenames in the root directory, type os.sep or +os.altsep immediately after an opening quote. (On Windows, +one can specify a drive first.) Move into subdirectories by typing a +directory name and a separator.

+

Instead of waiting, or after a box is closed, open a completion box +immediately with Show Completions on the Edit menu. The default hot +key is C-space. If one types a prefix for the desired name +before opening the box, the first match or near miss is made visible. +The result is the same as if one enters a prefix +after the box is displayed. Show Completions after a quote completes +filenames in the current directory instead of a root directory.

+

Hitting Tab after a prefix usually has the same effect as Show +Completions. (With no prefix, it indents.) However, if there is only +one match to the prefix, that match is immediately added to the editor +text without opening a box.

+

Invoking ‘Show Completions’, or hitting Tab after a prefix, +outside of a string and without a preceding ‘.’ opens a box with +keywords, builtin names, and available module-level names.

+

When editing code in an editor (as oppose to Shell), increase the +available module-level names by running your code +and not restarting the Shell thereafter. This is especially useful +after adding imports at the top of a file. This also increases +possible attribute completions.

+

Completion boxes initially exclude names beginning with ‘_’ or, for +modules, not included in ‘__all__’. The hidden names can be accessed +by typing ‘_’ after ‘.’, either before or after the box is opened.

+
+
+

Calltips

+

A calltip is shown automatically when one types ( after the name +of an accessible function. A function name expression may include +dots and subscripts. A calltip remains until it is clicked, the cursor +is moved out of the argument area, or ) is typed. Whenever the +cursor is in the argument part of a definition, select Edit and “Show +Call Tip” on the menu or enter its shortcut to display a calltip.

+

The calltip consists of the function’s signature and docstring up to +the latter’s first blank line or the fifth non-blank line. (Some builtin +functions lack an accessible signature.) A ‘/’ or ‘*’ in the signature +indicates that the preceding or following arguments are passed by +position or name (keyword) only. Details are subject to change.

+

In Shell, the accessible functions depends on what modules have been +imported into the user process, including those imported by Idle itself, +and which definitions have been run, all since the last restart.

For example, restart the Shell and enter itertools.count(. A calltip -appears because Idle imports itertools into the user process for its own use. -(This could change.) Enter turtle.write( and nothing appears. Idle does -not import turtle. The menu or shortcut do nothing either. Enter -import turtle and then turtle.write( will work.

-

In an editor, import statements have no effect until one runs the file. One -might want to run a file after writing the import statements at the top, -or immediately run an existing file before editing.

-
-
-

Code Context

+appears because Idle imports itertools into the user process for its own +use. (This could change.) Enter turtle.write( and nothing appears. +Idle does not itself import turtle. The menu entry and shortcut also do +nothing. Enter import turtle. Thereafter, turtle.write( +will display a calltip.

+

In an editor, import statements have no effect until one runs the file. +One might want to run a file after writing import statements, after +adding function definitions, or after opening an existing file.

+ +
+

Format block

+

Reformat Paragraph rewraps a block (‘paragraph’) of contiguous equally +indented non-blank comments, a similar block of text within a multiline +string, or a selected subset of either. +If needed, add a blank line to separate string from code. +Partial lines in a selection expand to complete lines. +The resulting lines have the same indent as before +but have maximum total length of N columns (characters). +Change the default N of 72 on the Window tab of IDLE Settings.

+
+
+

Code Context

Within an editor window containing Python code, code context can be toggled in order to show or hide a pane at the top of the window. When shown, this pane freezes the opening lines for block code, such as those beginning with @@ -535,47 +468,58 @@

Automatic indentation

The text and background colors for the context pane can be configured under the Highlights tab in the Configure IDLE dialog.

-

-
-

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.

+ +
+

Shell window

+

In IDLE’s Shell, enter, edit, and recall complete statements. (Most +consoles and terminals only work with a single physical line at a time).

+

Submit a single-line statement for execution by hitting Return +with the cursor anywhere on the line. If a line is extended with +Backslash (\), the cursor must be on the last physical line. +Submit a multi-line compound statement by entering a blank line after +the statement.

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 +until one hits Return, as specified above. +One may edit pasted code first. +If one pastes more than one statement into Shell, the result will be a SyntaxError when multiple statements are compiled as if they were one.

+

Lines containing RESTART mean that the user execution process has been +re-started. This occurs when the user execution process has crashed, +when one requests a restart on the Shell menu, or when one runs code +in an editor window.

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

  • -
  • C-d sends end-of-file; closes window if typed at a >>> prompt

  • -
  • Alt-/ (Expand word) is also useful to reduce typing

    -

    Command history

    +code interactively. IDLE’s Shell window also responds to the following:

      -
    • Alt-p retrieves previous command matching what you have typed. On -macOS use C-p.

    • -
    • Alt-n retrieves next. On macOS use C-n.

    • -
    • Return while on any previous command retrieves that command

    • -
    -
  • +
  • C-c attempts to interrupt statement execution (but may fail).

  • +
  • C-d closes Shell if typed at a >>> prompt.

  • +
  • Alt-p and Alt-n (C-p and C-n on macOS) +retrieve to the current prompt the previous or next previously +entered statement that matches anything already typed.

  • +
  • Return while the cursor is on any previous statement +appends the latter to anything already typed at the prompt.

-
-
-

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 keywords, builtin class and function names, names following class and def, strings, and comments. For any text window, these are the cursor (when present), found text (when possible), and selected text.

+

IDLE also highlights the soft keywords match, +case, and _ in +pattern-matching statements. However, this highlighting is not perfect and +will be incorrect in some rare cases, including some _-s in case +patterns.

Text coloring is done in the background, so uncolorized text is occasionally visible. To change the color scheme, use the Configure IDLE dialog Highlighting tab. The marking of debugger breakpoint lines in the editor and text in popups and dialogs is not user-configurable.

-
-