blob: 38ab4f114b88baac2b0ed65215e981d0e452223f [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001.. _idle:
2
Ned Deily50afcc02015-02-06 15:42:06 +11003IDLE
4====
5
Terry Jan Reedyfa089b92016-06-11 15:02:54 -04006.. moduleauthor:: Guido van Rossum <guido@python.org>
7
8**Source code:** :source:`Lib/idlelib/`
9
Georg Brandl116aa622007-08-15 14:28:22 +000010.. index::
Christian Heimes5b5e81c2007-12-31 16:14:33 +000011 single: IDLE
Georg Brandl116aa622007-08-15 14:28:22 +000012 single: Python Editor
13 single: Integrated Development Environment
14
Terry Jan Reedyfa089b92016-06-11 15:02:54 -040015--------------
Terry Jan Reedyf5684942014-12-04 00:54:59 -050016
Terry Jan Reedyd4705272015-10-02 23:22:59 -040017IDLE is Python's Integrated Development and Learning Environment.
Georg Brandl116aa622007-08-15 14:28:22 +000018
19IDLE has the following features:
20
Georg Brandlac6060c2008-05-17 18:44:45 +000021* coded in 100% pure Python, using the :mod:`tkinter` GUI toolkit
Georg Brandl116aa622007-08-15 14:28:22 +000022
Terry Jan Reedy0053c472015-09-24 03:09:43 -040023* cross-platform: works mostly the same on Windows, Unix, and Mac OS X
Georg Brandl116aa622007-08-15 14:28:22 +000024
Terry Jan Reedy6e10ec52015-09-23 20:00:33 -040025* Python shell window (interactive interpreter) with colorizing
26 of code input, output, and error messages
27
Andrew Svetlov1bd7f022013-01-14 19:27:36 +020028* multi-window text editor with multiple undo, Python colorizing,
Terry Jan Reedy6e10ec52015-09-23 20:00:33 -040029 smart indent, call tips, auto completion, and other features
Georg Brandl116aa622007-08-15 14:28:22 +000030
Terry Jan Reedy6e10ec52015-09-23 20:00:33 -040031* search within any window, replace within editor windows, and search
32 through multiple files (grep)
Georg Brandl116aa622007-08-15 14:28:22 +000033
Terry Jan Reedy6e10ec52015-09-23 20:00:33 -040034* debugger with persistent breakpoints, stepping, and viewing
35 of global and local namespaces
Georg Brandl116aa622007-08-15 14:28:22 +000036
Terry Jan Reedy6e10ec52015-09-23 20:00:33 -040037* configuration, browsers, and other dialogs
Georg Brandl116aa622007-08-15 14:28:22 +000038
39Menus
40-----
41
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050042IDLE has two main window types, the Shell window and the Editor window. It is
43possible to have multiple editor windows simultaneously. Output windows, such
44as used for Edit / Find in Files, are a subtype of edit window. They currently
45have the same top menu as Editor windows but a different default title and
46context menu.
47
48IDLE's menus dynamically change based on which window is currently selected.
49Each menu documented below indicates which window type it is associated with.
Georg Brandl116aa622007-08-15 14:28:22 +000050
Andrew Svetlov1bd7f022013-01-14 19:27:36 +020051File menu (Shell and Editor)
52^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +000053
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050054New File
55 Create a new file editing window.
Georg Brandl116aa622007-08-15 14:28:22 +000056
57Open...
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050058 Open an existing file with an Open dialog.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +020059
60Recent Files
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050061 Open a list of recent files. Click one to open it.
62
63Open Module...
64 Open an existing module (searches sys.path).
Georg Brandl116aa622007-08-15 14:28:22 +000065
Terry Jan Reedyf5684942014-12-04 00:54:59 -050066.. index::
67 single: Class browser
68 single: Path browser
69
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050070Class Browser
71 Show functions, classes, and methods in the current Editor file in a
72 tree structure. In the shell, open a module first.
Georg Brandl116aa622007-08-15 14:28:22 +000073
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050074Path Browser
75 Show sys.path directories, modules, functions, classes and methods in a
76 tree structure.
Georg Brandl116aa622007-08-15 14:28:22 +000077
Georg Brandl116aa622007-08-15 14:28:22 +000078Save
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050079 Save the current window to the associated file, if there is one. Windows
80 that have been changed since being opened or last saved have a \* before
81 and after the window title. If there is no associated file,
82 do Save As instead.
Georg Brandl116aa622007-08-15 14:28:22 +000083
84Save As...
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050085 Save the current window with a Save As dialog. The file saved becomes the
86 new associated file for the window.
Georg Brandl116aa622007-08-15 14:28:22 +000087
88Save Copy As...
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050089 Save the current window to different file without changing the associated
90 file.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +020091
92Print Window
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050093 Print the current window to the default printer.
Georg Brandl116aa622007-08-15 14:28:22 +000094
95Close
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050096 Close the current window (ask to save if unsaved).
Georg Brandl116aa622007-08-15 14:28:22 +000097
98Exit
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050099 Close all windows and quit IDLE (ask to save unsaved windows).
Georg Brandl116aa622007-08-15 14:28:22 +0000100
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200101Edit menu (Shell and Editor)
102^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +0000103
104Undo
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500105 Undo the last change to the current window. A maximum of 1000 changes may
106 be undone.
Georg Brandl116aa622007-08-15 14:28:22 +0000107
108Redo
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500109 Redo the last undone change to the current window.
Georg Brandl116aa622007-08-15 14:28:22 +0000110
111Cut
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500112 Copy selection into the system-wide clipboard; then delete the selection.
Georg Brandl116aa622007-08-15 14:28:22 +0000113
114Copy
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500115 Copy selection into the system-wide clipboard.
Georg Brandl116aa622007-08-15 14:28:22 +0000116
117Paste
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500118 Insert contents of the system-wide clipboard into the current window.
119
120The clipboard functions are also available in context menus.
Georg Brandl116aa622007-08-15 14:28:22 +0000121
122Select All
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500123 Select the entire contents of the current window.
Georg Brandl116aa622007-08-15 14:28:22 +0000124
125Find...
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500126 Open a search dialog with many options
Georg Brandl116aa622007-08-15 14:28:22 +0000127
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500128Find Again
129 Repeat the last search, if there is one.
Georg Brandl116aa622007-08-15 14:28:22 +0000130
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500131Find Selection
132 Search for the currently selected string, if there is one.
Georg Brandl116aa622007-08-15 14:28:22 +0000133
134Find in Files...
Serhiy Storchaka6a7b3a72016-04-17 08:32:47 +0300135 Open a file search dialog. Put results in a new output window.
Georg Brandl116aa622007-08-15 14:28:22 +0000136
137Replace...
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500138 Open a search-and-replace dialog.
Georg Brandl116aa622007-08-15 14:28:22 +0000139
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500140Go to Line
141 Move cursor to the line number requested and make that line visible.
Georg Brandl116aa622007-08-15 14:28:22 +0000142
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500143Show Completions
144 Open a scrollable list allowing selection of keywords and attributes. See
145 Completions in the Tips sections below.
146
147Expand Word
148 Expand a prefix you have typed to match a full word in the same window;
149 repeat to get a different expansion.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200150
151Show call tip
152 After an unclosed parenthesis for a function, open a small window with
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500153 function parameter hints.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200154
155Show surrounding parens
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500156 Highlight the surrounding parenthesis.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200157
158Format menu (Editor window only)
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500159^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200160
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500161Indent Region
162 Shift selected lines right by the indent width (default 4 spaces).
Georg Brandl116aa622007-08-15 14:28:22 +0000163
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500164Dedent Region
165 Shift selected lines left by the indent width (default 4 spaces).
Georg Brandl116aa622007-08-15 14:28:22 +0000166
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500167Comment Out Region
168 Insert ## in front of selected lines.
Georg Brandl116aa622007-08-15 14:28:22 +0000169
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500170Uncomment Region
171 Remove leading # or ## from selected lines.
Georg Brandl116aa622007-08-15 14:28:22 +0000172
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500173Tabify Region
174 Turn *leading* stretches of spaces into tabs. (Note: We recommend using
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200175 4 space blocks to indent Python code.)
Georg Brandl116aa622007-08-15 14:28:22 +0000176
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500177Untabify Region
178 Turn *all* tabs into the correct number of spaces.
Georg Brandl116aa622007-08-15 14:28:22 +0000179
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500180Toggle Tabs
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200181 Open a dialog to switch between indenting with spaces and tabs.
182
183New Indent Width
184 Open a dialog to change indent width. The accepted default by the Python
185 community is 4 spaces.
Georg Brandl116aa622007-08-15 14:28:22 +0000186
187Format Paragraph
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500188 Reformat the current blank-line-delimited paragraph in comment block or
189 multiline string or selected line in a string. All lines in the
190 paragraph will be formatted to less than N columns, where N defaults to 72.
Georg Brandl116aa622007-08-15 14:28:22 +0000191
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200192Strip trailing whitespace
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500193 Remove any space characters after the last non-space character of a line.
Georg Brandl116aa622007-08-15 14:28:22 +0000194
195.. index::
Georg Brandl116aa622007-08-15 14:28:22 +0000196 single: Run script
197
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200198Run menu (Editor window only)
199^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +0000200
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200201Python Shell
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500202 Open or wake up the Python Shell window.
Georg Brandl116aa622007-08-15 14:28:22 +0000203
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500204Check Module
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200205 Check the syntax of the module currently open in the Editor window. If the
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500206 module has not been saved IDLE will either prompt the user to save or
207 autosave, as selected in the General tab of the Idle Settings dialog. If
208 there is a syntax error, the approximate location is indicated in the
209 Editor window.
Georg Brandl116aa622007-08-15 14:28:22 +0000210
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500211Run Module
212 Do Check Module (above). If no error, restart the shell to clean the
Terry Jan Reedy8b5a9812015-09-24 01:39:30 -0400213 environment, then execute the module. Output is displayed in the Shell
214 window. Note that output requires use of ``print`` or ``write``.
215 When execution is complete, the Shell retains focus and displays a prompt.
216 At this point, one may interactively explore the result of execution.
217 This is similar to executing a file with ``python -i file`` at a command
218 line.
Georg Brandl116aa622007-08-15 14:28:22 +0000219
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200220Shell menu (Shell window only)
221^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Ned Deily2778d0d2012-10-20 13:25:34 -0700222
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200223View Last Restart
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500224 Scroll the shell window to the last Shell restart.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200225
226Restart Shell
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500227 Restart the shell to clean the environment.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200228
Terry Jan Reedy4b736762016-09-12 01:50:03 -0400229Interrupt Execution
230 Stop a running program.
231
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200232Debug menu (Shell window only)
233^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +0000234
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500235Go to File/Line
236 Look on the current line. with the cursor, and the line above for a filename
237 and line number. If found, open the file if not already open, and show the
238 line. Use this to view source lines referenced in an exception traceback
239 and lines found by Find in Files. Also available in the context menu of
240 the Shell window and Output windows.
Georg Brandl116aa622007-08-15 14:28:22 +0000241
242.. index::
Georg Brandl116aa622007-08-15 14:28:22 +0000243 single: debugger
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500244 single: stack viewer
245
246Debugger (toggle)
csabella9dc2b382017-04-29 18:28:36 -0400247 When activated, code entered in the Shell or run from an Editor will run
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500248 under the debugger. In the Editor, breakpoints can be set with the context
249 menu. This feature is still incomplete and somewhat experimental.
250
251Stack Viewer
252 Show the stack traceback of the last exception in a tree widget, with
253 access to locals and globals.
254
255Auto-open Stack Viewer
256 Toggle automatically opening the stack viewer on an unhandled exception.
Georg Brandl116aa622007-08-15 14:28:22 +0000257
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200258Options menu (Shell and Editor)
259^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +0000260
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200261Configure IDLE
Terry Jan Reedy93f35422015-10-13 22:03:51 -0400262 Open a configuration dialog and change preferences for the following:
263 fonts, indentation, keybindings, text color themes, startup windows and
264 size, additional help sources, and extensions (see below). On OS X,
265 open the configuration dialog by selecting Preferences in the application
266 menu. To use a new built-in color theme (IDLE Dark) with older IDLEs,
267 save it as a new custom theme.
Ned Deily2778d0d2012-10-20 13:25:34 -0700268
Terry Jan Reedy93f35422015-10-13 22:03:51 -0400269 Non-default user settings are saved in a .idlerc directory in the user's
270 home directory. Problems caused by bad user configuration files are solved
271 by editing or deleting one or more of the files in .idlerc.
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500272
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200273Code Context (toggle)(Editor Window only)
274 Open a pane at the top of the edit window which shows the block context
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500275 of the code which has scrolled above the top of the window.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200276
Ned Deilyccb416f2015-01-17 21:06:27 -0800277Window menu (Shell and Editor)
278^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200279
280Zoom Height
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500281 Toggles the window between normal size and maximum height. The initial size
282 defaults to 40 lines by 80 chars unless changed on the General tab of the
283 Configure IDLE dialog.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200284
285The rest of this menu lists the names of all open windows; select one to bring
286it to the foreground (deiconifying it if necessary).
287
288Help menu (Shell and Editor)
289^^^^^^^^^^^^^^^^^^^^^^^^^^^^
290
291About IDLE
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500292 Display version, copyright, license, credits, and more.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200293
294IDLE Help
295 Display a help file for IDLE detailing the menu options, basic editing and
296 navigation, and other tips.
297
298Python Docs
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500299 Access local Python documentation, if installed, or start a web browser
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200300 and open docs.python.org showing the latest Python documentation.
301
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500302Turtle Demo
303 Run the turtledemo module with example python code and turtle drawings.
304
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200305Additional help sources may be added here with the Configure IDLE dialog under
306the General tab.
307
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500308.. index::
309 single: Cut
310 single: Copy
311 single: Paste
312 single: Set Breakpoint
313 single: Clear Breakpoint
314 single: breakpoints
315
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500316Context Menus
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200317^^^^^^^^^^^^^^^^^^^^^^^^^^
318
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500319Open a context menu by right-clicking in a window (Control-click on OS X).
320Context menus have the standard clipboard functions also on the Edit menu.
Ned Deily2778d0d2012-10-20 13:25:34 -0700321
Andrew Svetlovd1837672012-11-01 22:41:19 +0200322Cut
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500323 Copy selection into the system-wide clipboard; then delete the selection.
Andrew Svetlovd1837672012-11-01 22:41:19 +0200324
325Copy
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500326 Copy selection into the system-wide clipboard.
Andrew Svetlovd1837672012-11-01 22:41:19 +0200327
328Paste
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500329 Insert contents of the system-wide clipboard into the current window.
330
331Editor windows also have breakpoint functions. Lines with a breakpoint set are
332specially marked. Breakpoints only have an effect when running under the
333debugger. Breakpoints for a file are saved in the user's .idlerc directory.
Andrew Svetlovd1837672012-11-01 22:41:19 +0200334
Ned Deily2778d0d2012-10-20 13:25:34 -0700335Set Breakpoint
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500336 Set a breakpoint on the current line.
Ned Deily2778d0d2012-10-20 13:25:34 -0700337
338Clear Breakpoint
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500339 Clear the breakpoint on that line.
Ned Deily2778d0d2012-10-20 13:25:34 -0700340
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500341Shell and Output windows have the following.
Andrew Svetlovd1837672012-11-01 22:41:19 +0200342
Ned Deily2778d0d2012-10-20 13:25:34 -0700343Go to file/line
344 Same as in Debug menu.
345
346
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200347Editing and navigation
348----------------------
Georg Brandl116aa622007-08-15 14:28:22 +0000349
Serhiy Storchaka0424eaf2015-09-12 17:45:25 +0300350In this section, 'C' refers to the :kbd:`Control` key on Windows and Unix and
351the :kbd:`Command` key on Mac OSX.
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500352
Georg Brandl116aa622007-08-15 14:28:22 +0000353* :kbd:`Backspace` deletes to the left; :kbd:`Del` deletes to the right
354
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200355* :kbd:`C-Backspace` delete word left; :kbd:`C-Del` delete word to the right
356
Georg Brandl116aa622007-08-15 14:28:22 +0000357* Arrow keys and :kbd:`Page Up`/:kbd:`Page Down` to move around
358
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200359* :kbd:`C-LeftArrow` and :kbd:`C-RightArrow` moves by words
360
Georg Brandl116aa622007-08-15 14:28:22 +0000361* :kbd:`Home`/:kbd:`End` go to begin/end of line
362
363* :kbd:`C-Home`/:kbd:`C-End` go to begin/end of file
364
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200365* Some useful Emacs bindings are inherited from Tcl/Tk:
366
367 * :kbd:`C-a` beginning of line
368
369 * :kbd:`C-e` end of line
370
371 * :kbd:`C-k` kill line (but doesn't put it in clipboard)
372
373 * :kbd:`C-l` center window around the insertion point
374
csabella9dc2b382017-04-29 18:28:36 -0400375 * :kbd:`C-b` go backward one character without deleting (usually you can
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200376 also use the cursor key for this)
377
378 * :kbd:`C-f` go forward one character without deleting (usually you can
379 also use the cursor key for this)
380
381 * :kbd:`C-p` go up one line (usually you can also use the cursor key for
382 this)
383
384 * :kbd:`C-d` delete next character
385
386Standard keybindings (like :kbd:`C-c` to copy and :kbd:`C-v` to paste)
387may work. Keybindings are selected in the Configure IDLE dialog.
Georg Brandl116aa622007-08-15 14:28:22 +0000388
389
390Automatic indentation
391^^^^^^^^^^^^^^^^^^^^^
392
393After a block-opening statement, the next line is indented by 4 spaces (in the
394Python Shell window by one tab). After certain keywords (break, return etc.)
395the next line is dedented. In leading indentation, :kbd:`Backspace` deletes up
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200396to 4 spaces if they are there. :kbd:`Tab` inserts spaces (in the Python
csabella9dc2b382017-04-29 18:28:36 -0400397Shell window one tab), number depends on Indent width. Currently, tabs
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200398are restricted to four spaces due to Tcl/Tk limitations.
Georg Brandl116aa622007-08-15 14:28:22 +0000399
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200400See also the indent/dedent region commands in the edit menu.
401
402Completions
403^^^^^^^^^^^
404
405Completions are supplied for functions, classes, and attributes of classes,
406both built-in and user-defined. Completions are also provided for
407filenames.
408
409The AutoCompleteWindow (ACW) will open after a predefined delay (default is
410two seconds) after a '.' or (in a string) an os.sep is typed. If after one
411of those characters (plus zero or more other characters) a tab is typed
412the ACW will open immediately if a possible continuation is found.
413
414If there is only one possible completion for the characters entered, a
415:kbd:`Tab` will supply that completion without opening the ACW.
416
417'Show Completions' will force open a completions window, by default the
418:kbd:`C-space` will open a completions window. In an empty
419string, this will contain the files in the current directory. On a
420blank line, it will contain the built-in and user-defined functions and
csabella9dc2b382017-04-29 18:28:36 -0400421classes in the current namespaces, plus any modules imported. If some
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200422characters have been entered, the ACW will attempt to be more specific.
423
424If a string of characters is typed, the ACW selection will jump to the
425entry most closely matching those characters. Entering a :kbd:`tab` will
426cause the longest non-ambiguous match to be entered in the Editor window or
427Shell. Two :kbd:`tab` in a row will supply the current ACW selection, as
428will return or a double click. Cursor keys, Page Up/Down, mouse selection,
429and the scroll wheel all operate on the ACW.
430
431"Hidden" attributes can be accessed by typing the beginning of hidden
432name after a '.', e.g. '_'. This allows access to modules with
433``__all__`` set, or to class-private attributes.
434
435Completions and the 'Expand Word' facility can save a lot of typing!
436
437Completions are currently limited to those in the namespaces. Names in
438an Editor window which are not via ``__main__`` and :data:`sys.modules` will
439not be found. Run the module once with your imports to correct this situation.
440Note that IDLE itself places quite a few modules in sys.modules, so
441much can be found by default, e.g. the re module.
442
443If you don't like the ACW popping up unbidden, simply make the delay
Terry Jan Reedy37f81352015-09-29 01:55:57 -0400444longer or disable the extension.
445
446Calltips
447^^^^^^^^
448
Alex Gaynor1cf2a802017-02-28 22:26:56 -0500449A calltip is shown when one types :kbd:`(` after the name of an *accessible*
Terry Jan Reedy37f81352015-09-29 01:55:57 -0400450function. A name expression may include dots and subscripts. A calltip
451remains until it is clicked, the cursor is moved out of the argument area,
452or :kbd:`)` is typed. When the cursor is in the argument part of a definition,
453the menu or shortcut display a calltip.
454
455A calltip consists of the function signature and the first line of the
456docstring. For builtins without an accessible signature, the calltip
457consists of all lines up the fifth line or the first blank line. These
458details may change.
459
460The set of *accessible* functions depends on what modules have been imported
461into the user process, including those imported by Idle itself,
462and what definitions have been run, all since the last restart.
463
464For example, restart the Shell and enter ``itertools.count(``. A calltip
465appears because Idle imports itertools into the user process for its own use.
466(This could change.) Enter ``turtle.write(`` and nothing appears. Idle does
467not import turtle. The menu or shortcut do nothing either. Enter
468``import turtle`` and then ``turtle.write(`` will work.
469
470In an editor, import statements have no effect until one runs the file. One
471might want to run a file after writing the import statements at the top,
472or immediately run an existing file before editing.
Georg Brandl116aa622007-08-15 14:28:22 +0000473
474Python Shell window
475^^^^^^^^^^^^^^^^^^^
476
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200477* :kbd:`C-c` interrupts executing command
Georg Brandl116aa622007-08-15 14:28:22 +0000478
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200479* :kbd:`C-d` sends end-of-file; closes window if typed at a ``>>>`` prompt
Georg Brandl116aa622007-08-15 14:28:22 +0000480
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200481* :kbd:`Alt-/` (Expand word) is also useful to reduce typing
Georg Brandl116aa622007-08-15 14:28:22 +0000482
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200483 Command history
Georg Brandl116aa622007-08-15 14:28:22 +0000484
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200485 * :kbd:`Alt-p` retrieves previous command matching what you have typed. On
486 OS X use :kbd:`C-p`.
Georg Brandl116aa622007-08-15 14:28:22 +0000487
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200488 * :kbd:`Alt-n` retrieves next. On OS X use :kbd:`C-n`.
Georg Brandl116aa622007-08-15 14:28:22 +0000489
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200490 * :kbd:`Return` while on any previous command retrieves that command
Georg Brandl116aa622007-08-15 14:28:22 +0000491
492
Terry Jan Reedyf660ce22015-09-24 23:13:49 -0400493Text colors
494^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +0000495
Terry Jan Reedyf660ce22015-09-24 23:13:49 -0400496Idle defaults to black on white text, but colors text with special meanings.
497For the shell, these are shell output, shell error, user output, and
498user error. For Python code, at the shell prompt or in an editor, these are
499keywords, builtin class and function names, names following ``class`` and
500``def``, strings, and comments. For any text window, these are the cursor (when
501present), found text (when possible), and selected text.
Georg Brandl116aa622007-08-15 14:28:22 +0000502
Terry Jan Reedyf660ce22015-09-24 23:13:49 -0400503Text coloring is done in the background, so uncolorized text is occasionally
504visible. To change the color scheme, use the Configure IDLE dialog
505Highlighting tab. The marking of debugger breakpoint lines in the editor and
506text in popups and dialogs is not user-configurable.
Georg Brandl116aa622007-08-15 14:28:22 +0000507
508
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400509Startup and code execution
510--------------------------
Benjamin Petersonf07d0022009-03-21 17:31:58 +0000511
512Upon startup with the ``-s`` option, IDLE will execute the file referenced by
513the environment variables :envvar:`IDLESTARTUP` or :envvar:`PYTHONSTARTUP`.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200514IDLE first checks for ``IDLESTARTUP``; if ``IDLESTARTUP`` is present the file
515referenced is run. If ``IDLESTARTUP`` is not present, IDLE checks for
Benjamin Petersonf07d0022009-03-21 17:31:58 +0000516``PYTHONSTARTUP``. Files referenced by these environment variables are
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200517convenient places to store functions that are used frequently from the IDLE
Benjamin Petersonf07d0022009-03-21 17:31:58 +0000518shell, or for executing import statements to import common modules.
519
520In addition, ``Tk`` also loads a startup file if it is present. Note that the
521Tk file is loaded unconditionally. This additional file is ``.Idle.py`` and is
522looked for in the user's home directory. Statements in this file will be
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500523executed in the Tk namespace, so this file is not useful for importing
524functions to be used from IDLE's Python shell.
Benjamin Petersonf07d0022009-03-21 17:31:58 +0000525
526
Georg Brandl116aa622007-08-15 14:28:22 +0000527Command line usage
528^^^^^^^^^^^^^^^^^^
529
Martin Panter1050d2d2016-07-26 11:18:21 +0200530.. code-block:: none
Georg Brandl116aa622007-08-15 14:28:22 +0000531
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400532 idle.py [-c command] [-d] [-e] [-h] [-i] [-r file] [-s] [-t title] [-] [arg] ...
Georg Brandl116aa622007-08-15 14:28:22 +0000533
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400534 -c command run command in the shell window
535 -d enable debugger and open shell window
536 -e open editor window
Terry Jan Reedy3399e1e2016-08-30 16:58:01 -0400537 -h print help message with legal combinations and exit
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400538 -i open shell window
539 -r file run file in shell window
540 -s run $IDLESTARTUP or $PYTHONSTARTUP first, in shell window
Georg Brandl116aa622007-08-15 14:28:22 +0000541 -t title set title of shell window
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400542 - run stdin in shell (- must be last option before args)
Georg Brandl116aa622007-08-15 14:28:22 +0000543
544If there are arguments:
545
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400546* If ``-``, ``-c``, or ``r`` is used, all arguments are placed in
547 ``sys.argv[1:...]`` and ``sys.argv[0]`` is set to ``''``, ``'-c'``,
548 or ``'-r'``. No editor window is opened, even if that is the default
549 set in the Options dialog.
Georg Brandl116aa622007-08-15 14:28:22 +0000550
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400551* Otherwise, arguments are files opened for editing and
552 ``sys.argv`` reflects the arguments passed to IDLE itself.
Georg Brandl116aa622007-08-15 14:28:22 +0000553
Georg Brandl116aa622007-08-15 14:28:22 +0000554
terryjreedy188aedf2017-06-13 21:32:16 -0400555Startup failure
556^^^^^^^^^^^^^^^
557
558IDLE uses a socket to communicate between the IDLE GUI process and the user
559code execution process. A connection must be established whenever the Shell
560starts or restarts. (The latter is indicated by a divider line that says
561'RESTART'). If the user process fails to connect to the GUI process, it
562displays a ``Tk`` error box with a 'cannot connect' message that directs the
563user here. It then exits.
564
565A common cause of failure is a user-written file with the same name as a
566standard library module, such as *random.py* and *tkinter.py*. When such a
567file is located in the same directory as a file that is about to be run,
568IDLE cannot import the stdlib file. The current fix is to rename the
569user file.
570
571Though less common than in the past, an antivirus or firewall program may
572stop the connection. If the program cannot be taught to allow the
573connection, then it must be turned off for IDLE to work. It is safe to
574allow this internal connection because no data is visible on external
575ports. A similar problem is a network mis-configuration that blocks
576connections.
577
578Python installation issues occasionally stop IDLE: multiple versions can
579clash, or a single installation might need admin access. If one undo the
580clash, or cannot or does not want to run as admin, it might be easiest to
581completely remove Python and start over.
582
583A zombie pythonw.exe process could be a problem. On Windows, use Task
584Manager to detect and stop one. Sometimes a restart initiated by a program
585crash or Keyboard Interrupt (control-C) may fail to connect. Dismissing
586the error box or Restart Shell on the Shell menu may fix a temporary problem.
587
588When IDLE first starts, it attempts to read user configuration files in
589~/.idlerc/ (~ is one's home directory). If there is a problem, an error
590message should be displayed. Leaving aside random disk glitches, this can
591be prevented by never editing the files by hand, using the configuration
592dialog, under Options, instead Options. Once it happens, the solution may
593be to delete one or more of the configuration files.
594
595If IDLE quits with no message, and it was not started from a console, try
596starting from a console (``python -m idlelib)`` and see if a message appears.
597
598
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400599IDLE-console differences
600^^^^^^^^^^^^^^^^^^^^^^^^
601
602As much as possible, the result of executing Python code with IDLE is the
603same as executing the same code in a console window. However, the different
csabella9dc2b382017-04-29 18:28:36 -0400604interface and operation occasionally affect visible results. For instance,
Terry Jan Reedy929d7f82016-05-02 18:30:02 -0400605``sys.modules`` starts with more entries.
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400606
Terry Jan Reedy929d7f82016-05-02 18:30:02 -0400607IDLE also replaces ``sys.stdin``, ``sys.stdout``, and ``sys.stderr`` with
608objects that get input from and send output to the Shell window.
609When this window has the focus, it controls the keyboard and screen.
610This is normally transparent, but functions that directly access the keyboard
611and screen will not work. If ``sys`` is reset with ``importlib.reload(sys)``,
Terry Jan Reedy1f8cc332016-08-25 01:22:30 -0400612IDLE's changes are lost and things like ``input``, ``raw_input``, and
Terry Jan Reedy929d7f82016-05-02 18:30:02 -0400613``print`` will not work correctly.
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400614
615With IDLE's Shell, one enters, edits, and recalls complete statements.
Terry Jan Reedy1f8cc332016-08-25 01:22:30 -0400616Some consoles only work with a single physical line at a time. IDLE uses
617``exec`` to run each statement. As a result, ``'__builtins__'`` is always
618defined for each statement.
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400619
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500620Running without a subprocess
621^^^^^^^^^^^^^^^^^^^^^^^^^^^^
622
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400623By default, IDLE executes user code in a separate subprocess via a socket,
Terry Jan Reedy6e10ec52015-09-23 20:00:33 -0400624which uses the internal loopback interface. This connection is not
625externally visible and no data is sent to or received from the Internet.
626If firewall software complains anyway, you can ignore it.
627
628If the attempt to make the socket connection fails, Idle will notify you.
629Such failures are sometimes transient, but if persistent, the problem
csabella9dc2b382017-04-29 18:28:36 -0400630may be either a firewall blocking the connection or misconfiguration of
Terry Jan Reedy6e10ec52015-09-23 20:00:33 -0400631a particular system. Until the problem is fixed, one can run Idle with
632the -n command line switch.
633
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500634If IDLE is started with the -n command line switch it will run in a
635single process and will not create the subprocess which runs the RPC
636Python execution server. This can be useful if Python cannot create
637the subprocess or the RPC socket interface on your platform. However,
638in this mode user code is not isolated from IDLE itself. Also, the
639environment is not restarted when Run/Run Module (F5) is selected. If
640your code has been modified, you must reload() the affected modules and
641re-import any specific items (e.g. from foo import baz) if the changes
642are to take effect. For these reasons, it is preferable to run IDLE
643with the default subprocess if at all possible.
644
645.. deprecated:: 3.4
646
Georg Brandl116aa622007-08-15 14:28:22 +0000647
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500648Help and preferences
649--------------------
650
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200651Additional help sources
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500652^^^^^^^^^^^^^^^^^^^^^^^
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200653
654IDLE includes a help menu entry called "Python Docs" that will open the
655extensive sources of help, including tutorials, available at docs.python.org.
656Selected URLs can be added or removed from the help menu at any time using the
657Configure IDLE dialog. See the IDLE help option in the help menu of IDLE for
658more information.
659
660
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500661Setting preferences
662^^^^^^^^^^^^^^^^^^^
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200663
664The font preferences, highlighting, keys, and general preferences can be
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500665changed via Configure IDLE on the Option menu. Keys can be user defined;
csabella9dc2b382017-04-29 18:28:36 -0400666IDLE ships with four built-in key sets. In addition, a user can create a
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500667custom key set in the Configure IDLE dialog under the keys tab.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200668
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500669
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200670Extensions
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500671^^^^^^^^^^
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200672
csabella9dc2b382017-04-29 18:28:36 -0400673IDLE contains an extension facility. Preferences for extensions can be
Terry Jan Reedyadb4cd22017-09-12 07:45:15 -0400674changed with the Extensions tab of the preferences dialog. See the
675beginning of config-extensions.def in the idlelib directory for further
676information. The only current default extension is zzdummy, an example
677also used for testing.