blob: 9ca92ceb5567d102b6e2bfd68f702170a5bf67f4 [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
229Debug menu (Shell window only)
230^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +0000231
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500232Go to File/Line
233 Look on the current line. with the cursor, and the line above for a filename
234 and line number. If found, open the file if not already open, and show the
235 line. Use this to view source lines referenced in an exception traceback
236 and lines found by Find in Files. Also available in the context menu of
237 the Shell window and Output windows.
Georg Brandl116aa622007-08-15 14:28:22 +0000238
239.. index::
Georg Brandl116aa622007-08-15 14:28:22 +0000240 single: debugger
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500241 single: stack viewer
242
243Debugger (toggle)
244 When actived, code entered in the Shell or run from an Editor will run
245 under the debugger. In the Editor, breakpoints can be set with the context
246 menu. This feature is still incomplete and somewhat experimental.
247
248Stack Viewer
249 Show the stack traceback of the last exception in a tree widget, with
250 access to locals and globals.
251
252Auto-open Stack Viewer
253 Toggle automatically opening the stack viewer on an unhandled exception.
Georg Brandl116aa622007-08-15 14:28:22 +0000254
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200255Options menu (Shell and Editor)
256^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +0000257
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200258Configure IDLE
Terry Jan Reedy93f35422015-10-13 22:03:51 -0400259 Open a configuration dialog and change preferences for the following:
260 fonts, indentation, keybindings, text color themes, startup windows and
261 size, additional help sources, and extensions (see below). On OS X,
262 open the configuration dialog by selecting Preferences in the application
263 menu. To use a new built-in color theme (IDLE Dark) with older IDLEs,
264 save it as a new custom theme.
Ned Deily2778d0d2012-10-20 13:25:34 -0700265
Terry Jan Reedy93f35422015-10-13 22:03:51 -0400266 Non-default user settings are saved in a .idlerc directory in the user's
267 home directory. Problems caused by bad user configuration files are solved
268 by editing or deleting one or more of the files in .idlerc.
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500269
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200270Code Context (toggle)(Editor Window only)
271 Open a pane at the top of the edit window which shows the block context
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500272 of the code which has scrolled above the top of the window.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200273
Ned Deilyccb416f2015-01-17 21:06:27 -0800274Window menu (Shell and Editor)
275^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200276
277Zoom Height
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500278 Toggles the window between normal size and maximum height. The initial size
279 defaults to 40 lines by 80 chars unless changed on the General tab of the
280 Configure IDLE dialog.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200281
282The rest of this menu lists the names of all open windows; select one to bring
283it to the foreground (deiconifying it if necessary).
284
285Help menu (Shell and Editor)
286^^^^^^^^^^^^^^^^^^^^^^^^^^^^
287
288About IDLE
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500289 Display version, copyright, license, credits, and more.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200290
291IDLE Help
292 Display a help file for IDLE detailing the menu options, basic editing and
293 navigation, and other tips.
294
295Python Docs
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500296 Access local Python documentation, if installed, or start a web browser
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200297 and open docs.python.org showing the latest Python documentation.
298
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500299Turtle Demo
300 Run the turtledemo module with example python code and turtle drawings.
301
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200302Additional help sources may be added here with the Configure IDLE dialog under
303the General tab.
304
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500305.. index::
306 single: Cut
307 single: Copy
308 single: Paste
309 single: Set Breakpoint
310 single: Clear Breakpoint
311 single: breakpoints
312
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500313Context Menus
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200314^^^^^^^^^^^^^^^^^^^^^^^^^^
315
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500316Open a context menu by right-clicking in a window (Control-click on OS X).
317Context menus have the standard clipboard functions also on the Edit menu.
Ned Deily2778d0d2012-10-20 13:25:34 -0700318
Andrew Svetlovd1837672012-11-01 22:41:19 +0200319Cut
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500320 Copy selection into the system-wide clipboard; then delete the selection.
Andrew Svetlovd1837672012-11-01 22:41:19 +0200321
322Copy
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500323 Copy selection into the system-wide clipboard.
Andrew Svetlovd1837672012-11-01 22:41:19 +0200324
325Paste
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500326 Insert contents of the system-wide clipboard into the current window.
327
328Editor windows also have breakpoint functions. Lines with a breakpoint set are
329specially marked. Breakpoints only have an effect when running under the
330debugger. Breakpoints for a file are saved in the user's .idlerc directory.
Andrew Svetlovd1837672012-11-01 22:41:19 +0200331
Ned Deily2778d0d2012-10-20 13:25:34 -0700332Set Breakpoint
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500333 Set a breakpoint on the current line.
Ned Deily2778d0d2012-10-20 13:25:34 -0700334
335Clear Breakpoint
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500336 Clear the breakpoint on that line.
Ned Deily2778d0d2012-10-20 13:25:34 -0700337
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500338Shell and Output windows have the following.
Andrew Svetlovd1837672012-11-01 22:41:19 +0200339
Ned Deily2778d0d2012-10-20 13:25:34 -0700340Go to file/line
341 Same as in Debug menu.
342
343
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200344Editing and navigation
345----------------------
Georg Brandl116aa622007-08-15 14:28:22 +0000346
Serhiy Storchaka0424eaf2015-09-12 17:45:25 +0300347In this section, 'C' refers to the :kbd:`Control` key on Windows and Unix and
348the :kbd:`Command` key on Mac OSX.
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500349
Georg Brandl116aa622007-08-15 14:28:22 +0000350* :kbd:`Backspace` deletes to the left; :kbd:`Del` deletes to the right
351
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200352* :kbd:`C-Backspace` delete word left; :kbd:`C-Del` delete word to the right
353
Georg Brandl116aa622007-08-15 14:28:22 +0000354* Arrow keys and :kbd:`Page Up`/:kbd:`Page Down` to move around
355
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200356* :kbd:`C-LeftArrow` and :kbd:`C-RightArrow` moves by words
357
Georg Brandl116aa622007-08-15 14:28:22 +0000358* :kbd:`Home`/:kbd:`End` go to begin/end of line
359
360* :kbd:`C-Home`/:kbd:`C-End` go to begin/end of file
361
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200362* Some useful Emacs bindings are inherited from Tcl/Tk:
363
364 * :kbd:`C-a` beginning of line
365
366 * :kbd:`C-e` end of line
367
368 * :kbd:`C-k` kill line (but doesn't put it in clipboard)
369
370 * :kbd:`C-l` center window around the insertion point
371
372 * :kbd:`C-b` go backwards one character without deleting (usually you can
373 also use the cursor key for this)
374
375 * :kbd:`C-f` go forward one character without deleting (usually you can
376 also use the cursor key for this)
377
378 * :kbd:`C-p` go up one line (usually you can also use the cursor key for
379 this)
380
381 * :kbd:`C-d` delete next character
382
383Standard keybindings (like :kbd:`C-c` to copy and :kbd:`C-v` to paste)
384may work. Keybindings are selected in the Configure IDLE dialog.
Georg Brandl116aa622007-08-15 14:28:22 +0000385
386
387Automatic indentation
388^^^^^^^^^^^^^^^^^^^^^
389
390After a block-opening statement, the next line is indented by 4 spaces (in the
391Python Shell window by one tab). After certain keywords (break, return etc.)
392the next line is dedented. In leading indentation, :kbd:`Backspace` deletes up
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200393to 4 spaces if they are there. :kbd:`Tab` inserts spaces (in the Python
394Shell window one tab), number depends on Indent width. Currently tabs
395are restricted to four spaces due to Tcl/Tk limitations.
Georg Brandl116aa622007-08-15 14:28:22 +0000396
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200397See also the indent/dedent region commands in the edit menu.
398
399Completions
400^^^^^^^^^^^
401
402Completions are supplied for functions, classes, and attributes of classes,
403both built-in and user-defined. Completions are also provided for
404filenames.
405
406The AutoCompleteWindow (ACW) will open after a predefined delay (default is
407two seconds) after a '.' or (in a string) an os.sep is typed. If after one
408of those characters (plus zero or more other characters) a tab is typed
409the ACW will open immediately if a possible continuation is found.
410
411If there is only one possible completion for the characters entered, a
412:kbd:`Tab` will supply that completion without opening the ACW.
413
414'Show Completions' will force open a completions window, by default the
415:kbd:`C-space` will open a completions window. In an empty
416string, this will contain the files in the current directory. On a
417blank line, it will contain the built-in and user-defined functions and
418classes in the current name spaces, plus any modules imported. If some
419characters have been entered, the ACW will attempt to be more specific.
420
421If a string of characters is typed, the ACW selection will jump to the
422entry most closely matching those characters. Entering a :kbd:`tab` will
423cause the longest non-ambiguous match to be entered in the Editor window or
424Shell. Two :kbd:`tab` in a row will supply the current ACW selection, as
425will return or a double click. Cursor keys, Page Up/Down, mouse selection,
426and the scroll wheel all operate on the ACW.
427
428"Hidden" attributes can be accessed by typing the beginning of hidden
429name after a '.', e.g. '_'. This allows access to modules with
430``__all__`` set, or to class-private attributes.
431
432Completions and the 'Expand Word' facility can save a lot of typing!
433
434Completions are currently limited to those in the namespaces. Names in
435an Editor window which are not via ``__main__`` and :data:`sys.modules` will
436not be found. Run the module once with your imports to correct this situation.
437Note that IDLE itself places quite a few modules in sys.modules, so
438much can be found by default, e.g. the re module.
439
440If you don't like the ACW popping up unbidden, simply make the delay
Terry Jan Reedy37f81352015-09-29 01:55:57 -0400441longer or disable the extension.
442
443Calltips
444^^^^^^^^
445
446A calltip is shown when one types :kbd:`(` after the name of an *acccessible*
447function. A name expression may include dots and subscripts. A calltip
448remains until it is clicked, the cursor is moved out of the argument area,
449or :kbd:`)` is typed. When the cursor is in the argument part of a definition,
450the menu or shortcut display a calltip.
451
452A calltip consists of the function signature and the first line of the
453docstring. For builtins without an accessible signature, the calltip
454consists of all lines up the fifth line or the first blank line. These
455details may change.
456
457The set of *accessible* functions depends on what modules have been imported
458into the user process, including those imported by Idle itself,
459and what definitions have been run, all since the last restart.
460
461For example, restart the Shell and enter ``itertools.count(``. A calltip
462appears because Idle imports itertools into the user process for its own use.
463(This could change.) Enter ``turtle.write(`` and nothing appears. Idle does
464not import turtle. The menu or shortcut do nothing either. Enter
465``import turtle`` and then ``turtle.write(`` will work.
466
467In an editor, import statements have no effect until one runs the file. One
468might want to run a file after writing the import statements at the top,
469or immediately run an existing file before editing.
Georg Brandl116aa622007-08-15 14:28:22 +0000470
471Python Shell window
472^^^^^^^^^^^^^^^^^^^
473
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200474* :kbd:`C-c` interrupts executing command
Georg Brandl116aa622007-08-15 14:28:22 +0000475
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200476* :kbd:`C-d` sends end-of-file; closes window if typed at a ``>>>`` prompt
Georg Brandl116aa622007-08-15 14:28:22 +0000477
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200478* :kbd:`Alt-/` (Expand word) is also useful to reduce typing
Georg Brandl116aa622007-08-15 14:28:22 +0000479
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200480 Command history
Georg Brandl116aa622007-08-15 14:28:22 +0000481
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200482 * :kbd:`Alt-p` retrieves previous command matching what you have typed. On
483 OS X use :kbd:`C-p`.
Georg Brandl116aa622007-08-15 14:28:22 +0000484
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200485 * :kbd:`Alt-n` retrieves next. On OS X use :kbd:`C-n`.
Georg Brandl116aa622007-08-15 14:28:22 +0000486
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200487 * :kbd:`Return` while on any previous command retrieves that command
Georg Brandl116aa622007-08-15 14:28:22 +0000488
489
Terry Jan Reedyf660ce22015-09-24 23:13:49 -0400490Text colors
491^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +0000492
Terry Jan Reedyf660ce22015-09-24 23:13:49 -0400493Idle defaults to black on white text, but colors text with special meanings.
494For the shell, these are shell output, shell error, user output, and
495user error. For Python code, at the shell prompt or in an editor, these are
496keywords, builtin class and function names, names following ``class`` and
497``def``, strings, and comments. For any text window, these are the cursor (when
498present), found text (when possible), and selected text.
Georg Brandl116aa622007-08-15 14:28:22 +0000499
Terry Jan Reedyf660ce22015-09-24 23:13:49 -0400500Text coloring is done in the background, so uncolorized text is occasionally
501visible. To change the color scheme, use the Configure IDLE dialog
502Highlighting tab. The marking of debugger breakpoint lines in the editor and
503text in popups and dialogs is not user-configurable.
Georg Brandl116aa622007-08-15 14:28:22 +0000504
505
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400506Startup and code execution
507--------------------------
Benjamin Petersonf07d0022009-03-21 17:31:58 +0000508
509Upon startup with the ``-s`` option, IDLE will execute the file referenced by
510the environment variables :envvar:`IDLESTARTUP` or :envvar:`PYTHONSTARTUP`.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200511IDLE first checks for ``IDLESTARTUP``; if ``IDLESTARTUP`` is present the file
512referenced is run. If ``IDLESTARTUP`` is not present, IDLE checks for
Benjamin Petersonf07d0022009-03-21 17:31:58 +0000513``PYTHONSTARTUP``. Files referenced by these environment variables are
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200514convenient places to store functions that are used frequently from the IDLE
Benjamin Petersonf07d0022009-03-21 17:31:58 +0000515shell, or for executing import statements to import common modules.
516
517In addition, ``Tk`` also loads a startup file if it is present. Note that the
518Tk file is loaded unconditionally. This additional file is ``.Idle.py`` and is
519looked for in the user's home directory. Statements in this file will be
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500520executed in the Tk namespace, so this file is not useful for importing
521functions to be used from IDLE's Python shell.
Benjamin Petersonf07d0022009-03-21 17:31:58 +0000522
523
Georg Brandl116aa622007-08-15 14:28:22 +0000524Command line usage
525^^^^^^^^^^^^^^^^^^
526
527::
528
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400529 idle.py [-c command] [-d] [-e] [-h] [-i] [-r file] [-s] [-t title] [-] [arg] ...
Georg Brandl116aa622007-08-15 14:28:22 +0000530
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400531 -c command run command in the shell window
532 -d enable debugger and open shell window
533 -e open editor window
534 -h print help message with legal combinatios and exit
535 -i open shell window
536 -r file run file in shell window
537 -s run $IDLESTARTUP or $PYTHONSTARTUP first, in shell window
Georg Brandl116aa622007-08-15 14:28:22 +0000538 -t title set title of shell window
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400539 - run stdin in shell (- must be last option before args)
Georg Brandl116aa622007-08-15 14:28:22 +0000540
541If there are arguments:
542
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400543* If ``-``, ``-c``, or ``r`` is used, all arguments are placed in
544 ``sys.argv[1:...]`` and ``sys.argv[0]`` is set to ``''``, ``'-c'``,
545 or ``'-r'``. No editor window is opened, even if that is the default
546 set in the Options dialog.
Georg Brandl116aa622007-08-15 14:28:22 +0000547
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400548* Otherwise, arguments are files opened for editing and
549 ``sys.argv`` reflects the arguments passed to IDLE itself.
Georg Brandl116aa622007-08-15 14:28:22 +0000550
Georg Brandl116aa622007-08-15 14:28:22 +0000551
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400552IDLE-console differences
553^^^^^^^^^^^^^^^^^^^^^^^^
554
555As much as possible, the result of executing Python code with IDLE is the
556same as executing the same code in a console window. However, the different
Terry Jan Reedy929d7f82016-05-02 18:30:02 -0400557interface and operation occasionally affects visible results. For instance,
558``sys.modules`` starts with more entries.
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400559
Terry Jan Reedy929d7f82016-05-02 18:30:02 -0400560IDLE also replaces ``sys.stdin``, ``sys.stdout``, and ``sys.stderr`` with
561objects that get input from and send output to the Shell window.
562When this window has the focus, it controls the keyboard and screen.
563This is normally transparent, but functions that directly access the keyboard
564and screen will not work. If ``sys`` is reset with ``importlib.reload(sys)``,
565IDLE's changes are lost and things li ke ``input``, ``raw_input``, and
566``print`` will not work correctly.
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400567
568With IDLE's Shell, one enters, edits, and recalls complete statements.
569Some consoles only work with a single physical line at a time.
570
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500571Running without a subprocess
572^^^^^^^^^^^^^^^^^^^^^^^^^^^^
573
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400574By default, IDLE executes user code in a separate subprocess via a socket,
Terry Jan Reedy6e10ec52015-09-23 20:00:33 -0400575which uses the internal loopback interface. This connection is not
576externally visible and no data is sent to or received from the Internet.
577If firewall software complains anyway, you can ignore it.
578
579If the attempt to make the socket connection fails, Idle will notify you.
580Such failures are sometimes transient, but if persistent, the problem
581may be either a firewall blocking the connecton or misconfiguration of
582a particular system. Until the problem is fixed, one can run Idle with
583the -n command line switch.
584
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500585If IDLE is started with the -n command line switch it will run in a
586single process and will not create the subprocess which runs the RPC
587Python execution server. This can be useful if Python cannot create
588the subprocess or the RPC socket interface on your platform. However,
589in this mode user code is not isolated from IDLE itself. Also, the
590environment is not restarted when Run/Run Module (F5) is selected. If
591your code has been modified, you must reload() the affected modules and
592re-import any specific items (e.g. from foo import baz) if the changes
593are to take effect. For these reasons, it is preferable to run IDLE
594with the default subprocess if at all possible.
595
596.. deprecated:: 3.4
597
Georg Brandl116aa622007-08-15 14:28:22 +0000598
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500599Help and preferences
600--------------------
601
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200602Additional help sources
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500603^^^^^^^^^^^^^^^^^^^^^^^
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200604
605IDLE includes a help menu entry called "Python Docs" that will open the
606extensive sources of help, including tutorials, available at docs.python.org.
607Selected URLs can be added or removed from the help menu at any time using the
608Configure IDLE dialog. See the IDLE help option in the help menu of IDLE for
609more information.
610
611
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500612Setting preferences
613^^^^^^^^^^^^^^^^^^^
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200614
615The font preferences, highlighting, keys, and general preferences can be
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500616changed via Configure IDLE on the Option menu. Keys can be user defined;
617IDLE ships with four built in key sets. In addition a user can create a
618custom key set in the Configure IDLE dialog under the keys tab.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200619
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500620
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200621Extensions
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500622^^^^^^^^^^
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200623
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500624IDLE contains an extension facility. Peferences for extensions can be
625changed with Configure Extensions. See the beginning of config-extensions.def
626in the idlelib directory for further information. The default extensions
627are currently:
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200628
629* FormatParagraph
630
631* AutoExpand
632
633* ZoomHeight
634
635* ScriptBinding
636
637* CallTips
638
639* ParenMatch
640
641* AutoComplete
642
643* CodeContext
644
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500645* RstripExtension