blob: 2140e85f048c306b90e8f078e468f5a4ece21e81 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001.. _idle:
2
Ned Deily50afcc02015-02-06 15:42:06 +11003IDLE
4====
5
Georg Brandl116aa622007-08-15 14:28:22 +00006.. index::
Christian Heimes5b5e81c2007-12-31 16:14:33 +00007 single: IDLE
Georg Brandl116aa622007-08-15 14:28:22 +00008 single: Python Editor
9 single: Integrated Development Environment
10
Terry Jan Reedy6e10ec52015-09-23 20:00:33 -040011.. moduleauthor:: Guido van Rossum <guido@python.org>
Terry Jan Reedyf5684942014-12-04 00:54:59 -050012
Terry Jan Reedyd4705272015-10-02 23:22:59 -040013IDLE is Python's Integrated Development and Learning Environment.
Georg Brandl116aa622007-08-15 14:28:22 +000014
15IDLE has the following features:
16
Georg Brandlac6060c2008-05-17 18:44:45 +000017* coded in 100% pure Python, using the :mod:`tkinter` GUI toolkit
Georg Brandl116aa622007-08-15 14:28:22 +000018
Terry Jan Reedy0053c472015-09-24 03:09:43 -040019* cross-platform: works mostly the same on Windows, Unix, and Mac OS X
Georg Brandl116aa622007-08-15 14:28:22 +000020
Terry Jan Reedy6e10ec52015-09-23 20:00:33 -040021* Python shell window (interactive interpreter) with colorizing
22 of code input, output, and error messages
23
Andrew Svetlov1bd7f022013-01-14 19:27:36 +020024* multi-window text editor with multiple undo, Python colorizing,
Terry Jan Reedy6e10ec52015-09-23 20:00:33 -040025 smart indent, call tips, auto completion, and other features
Georg Brandl116aa622007-08-15 14:28:22 +000026
Terry Jan Reedy6e10ec52015-09-23 20:00:33 -040027* search within any window, replace within editor windows, and search
28 through multiple files (grep)
Georg Brandl116aa622007-08-15 14:28:22 +000029
Terry Jan Reedy6e10ec52015-09-23 20:00:33 -040030* debugger with persistent breakpoints, stepping, and viewing
31 of global and local namespaces
Georg Brandl116aa622007-08-15 14:28:22 +000032
Terry Jan Reedy6e10ec52015-09-23 20:00:33 -040033* configuration, browsers, and other dialogs
Georg Brandl116aa622007-08-15 14:28:22 +000034
35Menus
36-----
37
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050038IDLE has two main window types, the Shell window and the Editor window. It is
39possible to have multiple editor windows simultaneously. Output windows, such
40as used for Edit / Find in Files, are a subtype of edit window. They currently
41have the same top menu as Editor windows but a different default title and
42context menu.
43
44IDLE's menus dynamically change based on which window is currently selected.
45Each menu documented below indicates which window type it is associated with.
Georg Brandl116aa622007-08-15 14:28:22 +000046
Andrew Svetlov1bd7f022013-01-14 19:27:36 +020047File menu (Shell and Editor)
48^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +000049
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050050New File
51 Create a new file editing window.
Georg Brandl116aa622007-08-15 14:28:22 +000052
53Open...
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050054 Open an existing file with an Open dialog.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +020055
56Recent Files
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050057 Open a list of recent files. Click one to open it.
58
59Open Module...
60 Open an existing module (searches sys.path).
Georg Brandl116aa622007-08-15 14:28:22 +000061
Terry Jan Reedyf5684942014-12-04 00:54:59 -050062.. index::
63 single: Class browser
64 single: Path browser
65
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050066Class Browser
67 Show functions, classes, and methods in the current Editor file in a
68 tree structure. In the shell, open a module first.
Georg Brandl116aa622007-08-15 14:28:22 +000069
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050070Path Browser
71 Show sys.path directories, modules, functions, classes and methods in a
72 tree structure.
Georg Brandl116aa622007-08-15 14:28:22 +000073
Georg Brandl116aa622007-08-15 14:28:22 +000074Save
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050075 Save the current window to the associated file, if there is one. Windows
76 that have been changed since being opened or last saved have a \* before
77 and after the window title. If there is no associated file,
78 do Save As instead.
Georg Brandl116aa622007-08-15 14:28:22 +000079
80Save As...
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050081 Save the current window with a Save As dialog. The file saved becomes the
82 new associated file for the window.
Georg Brandl116aa622007-08-15 14:28:22 +000083
84Save Copy As...
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050085 Save the current window to different file without changing the associated
86 file.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +020087
88Print Window
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050089 Print the current window to the default printer.
Georg Brandl116aa622007-08-15 14:28:22 +000090
91Close
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050092 Close the current window (ask to save if unsaved).
Georg Brandl116aa622007-08-15 14:28:22 +000093
94Exit
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050095 Close all windows and quit IDLE (ask to save unsaved windows).
Georg Brandl116aa622007-08-15 14:28:22 +000096
Andrew Svetlov1bd7f022013-01-14 19:27:36 +020097Edit menu (Shell and Editor)
98^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +000099
100Undo
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500101 Undo the last change to the current window. A maximum of 1000 changes may
102 be undone.
Georg Brandl116aa622007-08-15 14:28:22 +0000103
104Redo
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500105 Redo the last undone change to the current window.
Georg Brandl116aa622007-08-15 14:28:22 +0000106
107Cut
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500108 Copy selection into the system-wide clipboard; then delete the selection.
Georg Brandl116aa622007-08-15 14:28:22 +0000109
110Copy
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500111 Copy selection into the system-wide clipboard.
Georg Brandl116aa622007-08-15 14:28:22 +0000112
113Paste
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500114 Insert contents of the system-wide clipboard into the current window.
115
116The clipboard functions are also available in context menus.
Georg Brandl116aa622007-08-15 14:28:22 +0000117
118Select All
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500119 Select the entire contents of the current window.
Georg Brandl116aa622007-08-15 14:28:22 +0000120
121Find...
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500122 Open a search dialog with many options
Georg Brandl116aa622007-08-15 14:28:22 +0000123
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500124Find Again
125 Repeat the last search, if there is one.
Georg Brandl116aa622007-08-15 14:28:22 +0000126
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500127Find Selection
128 Search for the currently selected string, if there is one.
Georg Brandl116aa622007-08-15 14:28:22 +0000129
130Find in Files...
Serhiy Storchaka6a7b3a72016-04-17 08:32:47 +0300131 Open a file search dialog. Put results in a new output window.
Georg Brandl116aa622007-08-15 14:28:22 +0000132
133Replace...
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500134 Open a search-and-replace dialog.
Georg Brandl116aa622007-08-15 14:28:22 +0000135
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500136Go to Line
137 Move cursor to the line number requested and make that line visible.
Georg Brandl116aa622007-08-15 14:28:22 +0000138
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500139Show Completions
140 Open a scrollable list allowing selection of keywords and attributes. See
141 Completions in the Tips sections below.
142
143Expand Word
144 Expand a prefix you have typed to match a full word in the same window;
145 repeat to get a different expansion.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200146
147Show call tip
148 After an unclosed parenthesis for a function, open a small window with
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500149 function parameter hints.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200150
151Show surrounding parens
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500152 Highlight the surrounding parenthesis.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200153
154Format menu (Editor window only)
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500155^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200156
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500157Indent Region
158 Shift selected lines right by the indent width (default 4 spaces).
Georg Brandl116aa622007-08-15 14:28:22 +0000159
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500160Dedent Region
161 Shift selected lines left by the indent width (default 4 spaces).
Georg Brandl116aa622007-08-15 14:28:22 +0000162
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500163Comment Out Region
164 Insert ## in front of selected lines.
Georg Brandl116aa622007-08-15 14:28:22 +0000165
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500166Uncomment Region
167 Remove leading # or ## from selected lines.
Georg Brandl116aa622007-08-15 14:28:22 +0000168
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500169Tabify Region
170 Turn *leading* stretches of spaces into tabs. (Note: We recommend using
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200171 4 space blocks to indent Python code.)
Georg Brandl116aa622007-08-15 14:28:22 +0000172
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500173Untabify Region
174 Turn *all* tabs into the correct number of spaces.
Georg Brandl116aa622007-08-15 14:28:22 +0000175
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500176Toggle Tabs
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200177 Open a dialog to switch between indenting with spaces and tabs.
178
179New Indent Width
180 Open a dialog to change indent width. The accepted default by the Python
181 community is 4 spaces.
Georg Brandl116aa622007-08-15 14:28:22 +0000182
183Format Paragraph
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500184 Reformat the current blank-line-delimited paragraph in comment block or
185 multiline string or selected line in a string. All lines in the
186 paragraph will be formatted to less than N columns, where N defaults to 72.
Georg Brandl116aa622007-08-15 14:28:22 +0000187
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200188Strip trailing whitespace
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500189 Remove any space characters after the last non-space character of a line.
Georg Brandl116aa622007-08-15 14:28:22 +0000190
191.. index::
Georg Brandl116aa622007-08-15 14:28:22 +0000192 single: Run script
193
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200194Run menu (Editor window only)
195^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +0000196
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200197Python Shell
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500198 Open or wake up the Python Shell window.
Georg Brandl116aa622007-08-15 14:28:22 +0000199
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500200Check Module
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200201 Check the syntax of the module currently open in the Editor window. If the
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500202 module has not been saved IDLE will either prompt the user to save or
203 autosave, as selected in the General tab of the Idle Settings dialog. If
204 there is a syntax error, the approximate location is indicated in the
205 Editor window.
Georg Brandl116aa622007-08-15 14:28:22 +0000206
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500207Run Module
208 Do Check Module (above). If no error, restart the shell to clean the
Terry Jan Reedy8b5a9812015-09-24 01:39:30 -0400209 environment, then execute the module. Output is displayed in the Shell
210 window. Note that output requires use of ``print`` or ``write``.
211 When execution is complete, the Shell retains focus and displays a prompt.
212 At this point, one may interactively explore the result of execution.
213 This is similar to executing a file with ``python -i file`` at a command
214 line.
Georg Brandl116aa622007-08-15 14:28:22 +0000215
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200216Shell menu (Shell window only)
217^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Ned Deily2778d0d2012-10-20 13:25:34 -0700218
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200219View Last Restart
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500220 Scroll the shell window to the last Shell restart.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200221
222Restart Shell
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500223 Restart the shell to clean the environment.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200224
225Debug menu (Shell window only)
226^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +0000227
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500228Go to File/Line
229 Look on the current line. with the cursor, and the line above for a filename
230 and line number. If found, open the file if not already open, and show the
231 line. Use this to view source lines referenced in an exception traceback
232 and lines found by Find in Files. Also available in the context menu of
233 the Shell window and Output windows.
Georg Brandl116aa622007-08-15 14:28:22 +0000234
235.. index::
Georg Brandl116aa622007-08-15 14:28:22 +0000236 single: debugger
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500237 single: stack viewer
238
239Debugger (toggle)
240 When actived, code entered in the Shell or run from an Editor will run
241 under the debugger. In the Editor, breakpoints can be set with the context
242 menu. This feature is still incomplete and somewhat experimental.
243
244Stack Viewer
245 Show the stack traceback of the last exception in a tree widget, with
246 access to locals and globals.
247
248Auto-open Stack Viewer
249 Toggle automatically opening the stack viewer on an unhandled exception.
Georg Brandl116aa622007-08-15 14:28:22 +0000250
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200251Options menu (Shell and Editor)
252^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +0000253
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200254Configure IDLE
Terry Jan Reedy93f35422015-10-13 22:03:51 -0400255 Open a configuration dialog and change preferences for the following:
256 fonts, indentation, keybindings, text color themes, startup windows and
257 size, additional help sources, and extensions (see below). On OS X,
258 open the configuration dialog by selecting Preferences in the application
259 menu. To use a new built-in color theme (IDLE Dark) with older IDLEs,
260 save it as a new custom theme.
Ned Deily2778d0d2012-10-20 13:25:34 -0700261
Terry Jan Reedy93f35422015-10-13 22:03:51 -0400262 Non-default user settings are saved in a .idlerc directory in the user's
263 home directory. Problems caused by bad user configuration files are solved
264 by editing or deleting one or more of the files in .idlerc.
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500265
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200266Code Context (toggle)(Editor Window only)
267 Open a pane at the top of the edit window which shows the block context
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500268 of the code which has scrolled above the top of the window.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200269
Ned Deilyccb416f2015-01-17 21:06:27 -0800270Window menu (Shell and Editor)
271^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200272
273Zoom Height
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500274 Toggles the window between normal size and maximum height. The initial size
275 defaults to 40 lines by 80 chars unless changed on the General tab of the
276 Configure IDLE dialog.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200277
278The rest of this menu lists the names of all open windows; select one to bring
279it to the foreground (deiconifying it if necessary).
280
281Help menu (Shell and Editor)
282^^^^^^^^^^^^^^^^^^^^^^^^^^^^
283
284About IDLE
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500285 Display version, copyright, license, credits, and more.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200286
287IDLE Help
288 Display a help file for IDLE detailing the menu options, basic editing and
289 navigation, and other tips.
290
291Python Docs
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500292 Access local Python documentation, if installed, or start a web browser
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200293 and open docs.python.org showing the latest Python documentation.
294
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500295Turtle Demo
296 Run the turtledemo module with example python code and turtle drawings.
297
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200298Additional help sources may be added here with the Configure IDLE dialog under
299the General tab.
300
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500301.. index::
302 single: Cut
303 single: Copy
304 single: Paste
305 single: Set Breakpoint
306 single: Clear Breakpoint
307 single: breakpoints
308
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500309Context Menus
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200310^^^^^^^^^^^^^^^^^^^^^^^^^^
311
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500312Open a context menu by right-clicking in a window (Control-click on OS X).
313Context menus have the standard clipboard functions also on the Edit menu.
Ned Deily2778d0d2012-10-20 13:25:34 -0700314
Andrew Svetlovd1837672012-11-01 22:41:19 +0200315Cut
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500316 Copy selection into the system-wide clipboard; then delete the selection.
Andrew Svetlovd1837672012-11-01 22:41:19 +0200317
318Copy
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500319 Copy selection into the system-wide clipboard.
Andrew Svetlovd1837672012-11-01 22:41:19 +0200320
321Paste
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500322 Insert contents of the system-wide clipboard into the current window.
323
324Editor windows also have breakpoint functions. Lines with a breakpoint set are
325specially marked. Breakpoints only have an effect when running under the
326debugger. Breakpoints for a file are saved in the user's .idlerc directory.
Andrew Svetlovd1837672012-11-01 22:41:19 +0200327
Ned Deily2778d0d2012-10-20 13:25:34 -0700328Set Breakpoint
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500329 Set a breakpoint on the current line.
Ned Deily2778d0d2012-10-20 13:25:34 -0700330
331Clear Breakpoint
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500332 Clear the breakpoint on that line.
Ned Deily2778d0d2012-10-20 13:25:34 -0700333
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500334Shell and Output windows have the following.
Andrew Svetlovd1837672012-11-01 22:41:19 +0200335
Ned Deily2778d0d2012-10-20 13:25:34 -0700336Go to file/line
337 Same as in Debug menu.
338
339
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200340Editing and navigation
341----------------------
Georg Brandl116aa622007-08-15 14:28:22 +0000342
Serhiy Storchaka0424eaf2015-09-12 17:45:25 +0300343In this section, 'C' refers to the :kbd:`Control` key on Windows and Unix and
344the :kbd:`Command` key on Mac OSX.
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500345
Georg Brandl116aa622007-08-15 14:28:22 +0000346* :kbd:`Backspace` deletes to the left; :kbd:`Del` deletes to the right
347
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200348* :kbd:`C-Backspace` delete word left; :kbd:`C-Del` delete word to the right
349
Georg Brandl116aa622007-08-15 14:28:22 +0000350* Arrow keys and :kbd:`Page Up`/:kbd:`Page Down` to move around
351
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200352* :kbd:`C-LeftArrow` and :kbd:`C-RightArrow` moves by words
353
Georg Brandl116aa622007-08-15 14:28:22 +0000354* :kbd:`Home`/:kbd:`End` go to begin/end of line
355
356* :kbd:`C-Home`/:kbd:`C-End` go to begin/end of file
357
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200358* Some useful Emacs bindings are inherited from Tcl/Tk:
359
360 * :kbd:`C-a` beginning of line
361
362 * :kbd:`C-e` end of line
363
364 * :kbd:`C-k` kill line (but doesn't put it in clipboard)
365
366 * :kbd:`C-l` center window around the insertion point
367
368 * :kbd:`C-b` go backwards one character without deleting (usually you can
369 also use the cursor key for this)
370
371 * :kbd:`C-f` go forward one character without deleting (usually you can
372 also use the cursor key for this)
373
374 * :kbd:`C-p` go up one line (usually you can also use the cursor key for
375 this)
376
377 * :kbd:`C-d` delete next character
378
379Standard keybindings (like :kbd:`C-c` to copy and :kbd:`C-v` to paste)
380may work. Keybindings are selected in the Configure IDLE dialog.
Georg Brandl116aa622007-08-15 14:28:22 +0000381
382
383Automatic indentation
384^^^^^^^^^^^^^^^^^^^^^
385
386After a block-opening statement, the next line is indented by 4 spaces (in the
387Python Shell window by one tab). After certain keywords (break, return etc.)
388the next line is dedented. In leading indentation, :kbd:`Backspace` deletes up
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200389to 4 spaces if they are there. :kbd:`Tab` inserts spaces (in the Python
390Shell window one tab), number depends on Indent width. Currently tabs
391are restricted to four spaces due to Tcl/Tk limitations.
Georg Brandl116aa622007-08-15 14:28:22 +0000392
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200393See also the indent/dedent region commands in the edit menu.
394
395Completions
396^^^^^^^^^^^
397
398Completions are supplied for functions, classes, and attributes of classes,
399both built-in and user-defined. Completions are also provided for
400filenames.
401
402The AutoCompleteWindow (ACW) will open after a predefined delay (default is
403two seconds) after a '.' or (in a string) an os.sep is typed. If after one
404of those characters (plus zero or more other characters) a tab is typed
405the ACW will open immediately if a possible continuation is found.
406
407If there is only one possible completion for the characters entered, a
408:kbd:`Tab` will supply that completion without opening the ACW.
409
410'Show Completions' will force open a completions window, by default the
411:kbd:`C-space` will open a completions window. In an empty
412string, this will contain the files in the current directory. On a
413blank line, it will contain the built-in and user-defined functions and
414classes in the current name spaces, plus any modules imported. If some
415characters have been entered, the ACW will attempt to be more specific.
416
417If a string of characters is typed, the ACW selection will jump to the
418entry most closely matching those characters. Entering a :kbd:`tab` will
419cause the longest non-ambiguous match to be entered in the Editor window or
420Shell. Two :kbd:`tab` in a row will supply the current ACW selection, as
421will return or a double click. Cursor keys, Page Up/Down, mouse selection,
422and the scroll wheel all operate on the ACW.
423
424"Hidden" attributes can be accessed by typing the beginning of hidden
425name after a '.', e.g. '_'. This allows access to modules with
426``__all__`` set, or to class-private attributes.
427
428Completions and the 'Expand Word' facility can save a lot of typing!
429
430Completions are currently limited to those in the namespaces. Names in
431an Editor window which are not via ``__main__`` and :data:`sys.modules` will
432not be found. Run the module once with your imports to correct this situation.
433Note that IDLE itself places quite a few modules in sys.modules, so
434much can be found by default, e.g. the re module.
435
436If you don't like the ACW popping up unbidden, simply make the delay
Terry Jan Reedy37f81352015-09-29 01:55:57 -0400437longer or disable the extension.
438
439Calltips
440^^^^^^^^
441
442A calltip is shown when one types :kbd:`(` after the name of an *acccessible*
443function. A name expression may include dots and subscripts. A calltip
444remains until it is clicked, the cursor is moved out of the argument area,
445or :kbd:`)` is typed. When the cursor is in the argument part of a definition,
446the menu or shortcut display a calltip.
447
448A calltip consists of the function signature and the first line of the
449docstring. For builtins without an accessible signature, the calltip
450consists of all lines up the fifth line or the first blank line. These
451details may change.
452
453The set of *accessible* functions depends on what modules have been imported
454into the user process, including those imported by Idle itself,
455and what definitions have been run, all since the last restart.
456
457For example, restart the Shell and enter ``itertools.count(``. A calltip
458appears because Idle imports itertools into the user process for its own use.
459(This could change.) Enter ``turtle.write(`` and nothing appears. Idle does
460not import turtle. The menu or shortcut do nothing either. Enter
461``import turtle`` and then ``turtle.write(`` will work.
462
463In an editor, import statements have no effect until one runs the file. One
464might want to run a file after writing the import statements at the top,
465or immediately run an existing file before editing.
Georg Brandl116aa622007-08-15 14:28:22 +0000466
467Python Shell window
468^^^^^^^^^^^^^^^^^^^
469
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200470* :kbd:`C-c` interrupts executing command
Georg Brandl116aa622007-08-15 14:28:22 +0000471
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200472* :kbd:`C-d` sends end-of-file; closes window if typed at a ``>>>`` prompt
Georg Brandl116aa622007-08-15 14:28:22 +0000473
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200474* :kbd:`Alt-/` (Expand word) is also useful to reduce typing
Georg Brandl116aa622007-08-15 14:28:22 +0000475
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200476 Command history
Georg Brandl116aa622007-08-15 14:28:22 +0000477
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200478 * :kbd:`Alt-p` retrieves previous command matching what you have typed. On
479 OS X use :kbd:`C-p`.
Georg Brandl116aa622007-08-15 14:28:22 +0000480
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200481 * :kbd:`Alt-n` retrieves next. On OS X use :kbd:`C-n`.
Georg Brandl116aa622007-08-15 14:28:22 +0000482
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200483 * :kbd:`Return` while on any previous command retrieves that command
Georg Brandl116aa622007-08-15 14:28:22 +0000484
485
Terry Jan Reedyf660ce22015-09-24 23:13:49 -0400486Text colors
487^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +0000488
Terry Jan Reedyf660ce22015-09-24 23:13:49 -0400489Idle defaults to black on white text, but colors text with special meanings.
490For the shell, these are shell output, shell error, user output, and
491user error. For Python code, at the shell prompt or in an editor, these are
492keywords, builtin class and function names, names following ``class`` and
493``def``, strings, and comments. For any text window, these are the cursor (when
494present), found text (when possible), and selected text.
Georg Brandl116aa622007-08-15 14:28:22 +0000495
Terry Jan Reedyf660ce22015-09-24 23:13:49 -0400496Text coloring is done in the background, so uncolorized text is occasionally
497visible. To change the color scheme, use the Configure IDLE dialog
498Highlighting tab. The marking of debugger breakpoint lines in the editor and
499text in popups and dialogs is not user-configurable.
Georg Brandl116aa622007-08-15 14:28:22 +0000500
501
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400502Startup and code execution
503--------------------------
Benjamin Petersonf07d0022009-03-21 17:31:58 +0000504
505Upon startup with the ``-s`` option, IDLE will execute the file referenced by
506the environment variables :envvar:`IDLESTARTUP` or :envvar:`PYTHONSTARTUP`.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200507IDLE first checks for ``IDLESTARTUP``; if ``IDLESTARTUP`` is present the file
508referenced is run. If ``IDLESTARTUP`` is not present, IDLE checks for
Benjamin Petersonf07d0022009-03-21 17:31:58 +0000509``PYTHONSTARTUP``. Files referenced by these environment variables are
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200510convenient places to store functions that are used frequently from the IDLE
Benjamin Petersonf07d0022009-03-21 17:31:58 +0000511shell, or for executing import statements to import common modules.
512
513In addition, ``Tk`` also loads a startup file if it is present. Note that the
514Tk file is loaded unconditionally. This additional file is ``.Idle.py`` and is
515looked for in the user's home directory. Statements in this file will be
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500516executed in the Tk namespace, so this file is not useful for importing
517functions to be used from IDLE's Python shell.
Benjamin Petersonf07d0022009-03-21 17:31:58 +0000518
519
Georg Brandl116aa622007-08-15 14:28:22 +0000520Command line usage
521^^^^^^^^^^^^^^^^^^
522
523::
524
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400525 idle.py [-c command] [-d] [-e] [-h] [-i] [-r file] [-s] [-t title] [-] [arg] ...
Georg Brandl116aa622007-08-15 14:28:22 +0000526
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400527 -c command run command in the shell window
528 -d enable debugger and open shell window
529 -e open editor window
530 -h print help message with legal combinatios and exit
531 -i open shell window
532 -r file run file in shell window
533 -s run $IDLESTARTUP or $PYTHONSTARTUP first, in shell window
Georg Brandl116aa622007-08-15 14:28:22 +0000534 -t title set title of shell window
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400535 - run stdin in shell (- must be last option before args)
Georg Brandl116aa622007-08-15 14:28:22 +0000536
537If there are arguments:
538
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400539* If ``-``, ``-c``, or ``r`` is used, all arguments are placed in
540 ``sys.argv[1:...]`` and ``sys.argv[0]`` is set to ``''``, ``'-c'``,
541 or ``'-r'``. No editor window is opened, even if that is the default
542 set in the Options dialog.
Georg Brandl116aa622007-08-15 14:28:22 +0000543
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400544* Otherwise, arguments are files opened for editing and
545 ``sys.argv`` reflects the arguments passed to IDLE itself.
Georg Brandl116aa622007-08-15 14:28:22 +0000546
Georg Brandl116aa622007-08-15 14:28:22 +0000547
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400548IDLE-console differences
549^^^^^^^^^^^^^^^^^^^^^^^^
550
551As much as possible, the result of executing Python code with IDLE is the
552same as executing the same code in a console window. However, the different
Terry Jan Reedy929d7f82016-05-02 18:30:02 -0400553interface and operation occasionally affects visible results. For instance,
554``sys.modules`` starts with more entries.
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400555
Terry Jan Reedy929d7f82016-05-02 18:30:02 -0400556IDLE also replaces ``sys.stdin``, ``sys.stdout``, and ``sys.stderr`` with
557objects that get input from and send output to the Shell window.
558When this window has the focus, it controls the keyboard and screen.
559This is normally transparent, but functions that directly access the keyboard
560and screen will not work. If ``sys`` is reset with ``importlib.reload(sys)``,
561IDLE's changes are lost and things li ke ``input``, ``raw_input``, and
562``print`` will not work correctly.
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400563
564With IDLE's Shell, one enters, edits, and recalls complete statements.
565Some consoles only work with a single physical line at a time.
566
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500567Running without a subprocess
568^^^^^^^^^^^^^^^^^^^^^^^^^^^^
569
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400570By default, IDLE executes user code in a separate subprocess via a socket,
Terry Jan Reedy6e10ec52015-09-23 20:00:33 -0400571which uses the internal loopback interface. This connection is not
572externally visible and no data is sent to or received from the Internet.
573If firewall software complains anyway, you can ignore it.
574
575If the attempt to make the socket connection fails, Idle will notify you.
576Such failures are sometimes transient, but if persistent, the problem
577may be either a firewall blocking the connecton or misconfiguration of
578a particular system. Until the problem is fixed, one can run Idle with
579the -n command line switch.
580
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500581If IDLE is started with the -n command line switch it will run in a
582single process and will not create the subprocess which runs the RPC
583Python execution server. This can be useful if Python cannot create
584the subprocess or the RPC socket interface on your platform. However,
585in this mode user code is not isolated from IDLE itself. Also, the
586environment is not restarted when Run/Run Module (F5) is selected. If
587your code has been modified, you must reload() the affected modules and
588re-import any specific items (e.g. from foo import baz) if the changes
589are to take effect. For these reasons, it is preferable to run IDLE
590with the default subprocess if at all possible.
591
592.. deprecated:: 3.4
593
Georg Brandl116aa622007-08-15 14:28:22 +0000594
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500595Help and preferences
596--------------------
597
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200598Additional help sources
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500599^^^^^^^^^^^^^^^^^^^^^^^
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200600
601IDLE includes a help menu entry called "Python Docs" that will open the
602extensive sources of help, including tutorials, available at docs.python.org.
603Selected URLs can be added or removed from the help menu at any time using the
604Configure IDLE dialog. See the IDLE help option in the help menu of IDLE for
605more information.
606
607
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500608Setting preferences
609^^^^^^^^^^^^^^^^^^^
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200610
611The font preferences, highlighting, keys, and general preferences can be
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500612changed via Configure IDLE on the Option menu. Keys can be user defined;
613IDLE ships with four built in key sets. In addition a user can create a
614custom key set in the Configure IDLE dialog under the keys tab.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200615
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500616
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200617Extensions
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500618^^^^^^^^^^
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200619
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500620IDLE contains an extension facility. Peferences for extensions can be
621changed with Configure Extensions. See the beginning of config-extensions.def
622in the idlelib directory for further information. The default extensions
623are currently:
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200624
625* FormatParagraph
626
627* AutoExpand
628
629* ZoomHeight
630
631* ScriptBinding
632
633* CallTips
634
635* ParenMatch
636
637* AutoComplete
638
639* CodeContext
640
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500641* RstripExtension