IDLE has two main window types, the Shell window and the Editor window. It ispossible to have multiple editor windows simultaneously. On Windows andLinux, each has its own top menu. Each menu documented below indicateswhich window type it is associated with.
On macOS, there is one application menu. It dynamically changes accordingto the window currently selected. It has an IDLE menu, and some entriesdescribed below are moved around to conform to Apple guidelines.
Save the current window to the associated file, if there is one. Windowsthat have been changed since being opened or last saved have a * beforeand after the window title. If there is no associated file,do Save As instead.
Close the current window (if an unsaved editor, ask to save; if an unsavedShell, ask to quit execution). Calling exit() or close() in the Shellwindow also closes Shell. If this is the only window, also exit IDLE.
Reformat the current blank-line-delimited paragraph in comment block ormultiline string or selected line in a string. All lines in theparagraph will be formatted to less than N columns, where N defaults to 72.
Remove trailing space and other whitespace characters after the lastnon-whitespace character of a line by applying str.rstrip to each line,including lines within multiline strings. Except for Shell windows,remove extra newlines at the end of the file.
Do Check Module. If no error, restart the shell to clean theenvironment, then execute the module. Output is displayed in the Shellwindow. Note that output requires use of print or write.When execution is complete, the Shell retains focus and displays a prompt.At this point, one may interactively explore the result of execution.This is similar to executing a file with python -i file at a commandline.
Check the syntax of the module currently open in the Editor window. If themodule has not been saved IDLE will either prompt the user to save orautosave, as selected in the General tab of the Idle Settings dialog. Ifthere is a syntax error, the approximate location is indicated in theEditor window.
Look on the current line. with the cursor, and the line above for a filenameand line number. If found, open the file if not already open, and show theline. Use this to view source lines referenced in an exception tracebackand lines found by Find in Files. Also available in the context menu ofthe Shell window and Output windows.
When activated, code entered in the Shell or run from an Editor will rununder the debugger. In the Editor, breakpoints can be set with the contextmenu. This feature is still incomplete and somewhat experimental.
Open a configuration dialog and change preferences for the following:fonts, indentation, keybindings, text color themes, startup windows andsize, additional help sources, and extensions. On macOS, open theconfiguration dialog by selecting Preferences in the applicationmenu. For more details, seeSetting preferences under Help and preferences.
Toggles the window between normal size and maximum height. The initial sizedefaults to 40 lines by 80 chars unless changed on the General tab of theConfigure IDLE dialog. The maximum height for a screen is determined bymomentarily maximizing a window the first time one is zoomed on the screen.Changing screen settings may invalidate the saved height. This toggle hasno effect when a window is maximized.
The IDLE insertion cursor is a thin vertical bar between characterpositions. When characters are entered, the insertion cursor andeverything to its right moves right one character andthe new character is entered in the new space.
After a block-opening statement, the next line is indented by 4 spaces (in thePython Shell window by one tab). After certain keywords (break, return etc.)the next line is dedented. In leading indentation, Backspace deletes upto 4 spaces if they are there. Tab inserts spaces (in the PythonShell window one tab), number depends on Indent width. Currently, tabsare restricted to four spaces due to Tcl/Tk limitations.
Any selection becomes a search target. However, only selections withina line work because searches are only performed within lines with theterminal newline removed. If [x] Regular expression is checked, thetarget is interpreted according to the Python re module.
Completions are supplied, when requested and available, for modulenames, attributes of classes or functions, or filenames. Each requestmethod displays a completion box with existing names. (See tabcompletions below for an exception.) For any box, change the namebeing completed and the item highlighted in the box bytyping 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.
Instead of waiting, or after a box is closed, open a completion boximmediately with Show Completions on the Edit menu. The default hotkey is C-space. If one types a prefix for the desired namebefore opening the box, the first match or near miss is made visible.The result is the same as if one enters a prefixafter the box is displayed. Show Completions after a quote completesfilenames in the current directory instead of a root directory.
Hitting Tab after a prefix usually has the same effect as ShowCompletions. (With no prefix, it indents.) However, if there is onlyone match to the prefix, that match is immediately added to the editortext without opening a box.
When editing code in an editor (as oppose to Shell), increase theavailable module-level names by running your codeand not restarting the Shell thereafter. This is especially usefulafter adding imports at the top of a file. This also increasespossible attribute completions.
In Shell, the accessible functions depends on what modules have beenimported 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 calltipappears because Idle imports itertools into the user process for its ownuse. (This could change.) Enter turtle.write( and nothing appears.Idle does not itself import turtle. The menu entry and shortcut also donothing. 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, afteradding function definitions, or after opening an existing file.
Within an editor window containing Python code, code context can be toggledin order to show or hide a pane at the top of the window. When shown, thispane freezes the opening lines for block code, such as those beginning withclass, def, or if keywords, that would have otherwise scrolledout of view. The size of the pane will be expanded and contracted as neededto show the all current levels of context, up to the maximum number oflines defined in the Configure IDLE dialog (which defaults to 15). If thereare no current context lines and the feature is toggled on, a single blankline will display. Clicking on a line in the context pane will move thatline to the top of the editor.
Submit a single-line statement for execution by hitting Returnwith the cursor anywhere on the line. If a line is extended withBackslash (\), the cursor must be on the last physical line.Submit a multi-line compound statement by entering a blank line afterthe statement.
When one pastes code into Shell, it is not compiled and possibly executeduntil 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 aSyntaxError when multiple statements are compiled as if they were one.
Lines containing RESTART mean that the user execution process has beenre-started. This occurs when the user execution process has crashed,when one requests a restart on the Shell menu, or when one runs codein an editor window.
Idle defaults to black on white text, but colors text with special meanings.For the shell, these are shell output, shell error, user output, anduser error. For Python code, at the shell prompt or in an editor, these arekeywords, builtin class and function names, names following class anddef, strings, and comments. For any text window, these are the cursor (whenpresent), found text (when possible), and selected text.
IDLE also highlights the soft keywords match,case, and _ inpattern-matching statements. However, this highlighting is not perfect andwill be incorrect in some rare cases, including some _-s in casepatterns.
Text coloring is done in the background, so uncolorized text is occasionallyvisible. To change the color scheme, use the Configure IDLE dialogHighlighting tab. The marking of debugger breakpoint lines in the editor andtext in popups and dialogs is not user-configurable.
Upon startup with the -s option, IDLE will execute the file referenced bythe environment variables IDLESTARTUP or PYTHONSTARTUP.IDLE first checks for IDLESTARTUP; if IDLESTARTUP is present the filereferenced is run. If IDLESTARTUP is not present, IDLE checks forPYTHONSTARTUP. Files referenced by these environment variables areconvenient places to store functions that are used frequently from the IDLEshell, or for executing import statements to import common modules.
A common cause of failure is a user-written file with the same name as astandard library module, such as random.py and tkinter.py. When such afile is located in the same directory as a file that is about to be run,IDLE cannot import the stdlib file. The current fix is to rename theuser file.
Though less common than in the past, an antivirus or firewall program maystop the connection. If the program cannot be taught to allow theconnection, then it must be turned off for IDLE to work. It is safe toallow this internal connection because no data is visible on externalports. A similar problem is a network mis-configuration that blocksconnections.
Python installation issues occasionally stop IDLE: multiple versions canclash, or a single installation might need admin access. If one undo theclash, or cannot or does not want to run as admin, it might be easiest tocompletely remove Python and start over.
d3342ee215