blob: a461e51c21570cc2734babe06e795fecb53cc009 [file] [log] [blame]
Georg Brandl8ec7f652007-08-15 14:28:01 +00001.. _idle:
2
Ned Deilye0944c92015-02-06 15:41:27 +11003IDLE
4====
5
Georg Brandl8ec7f652007-08-15 14:28:01 +00006.. index::
Georg Brandlb19be572007-12-29 10:57:00 +00007 single: IDLE
Georg Brandl8ec7f652007-08-15 14:28:01 +00008 single: Python Editor
9 single: Integrated Development Environment
10
Terry Jan Reedy6741a5a2015-09-23 20:00:22 -040011.. moduleauthor:: Guido van Rossum <guido@python.org>
Terry Jan Reedyeb405892014-12-04 00:55:46 -050012
Terry Jan Reedy195fc2f2015-10-02 23:22:54 -040013IDLE is Python's Integrated Development and Learning Environment.
Georg Brandl8ec7f652007-08-15 14:28:01 +000014
15IDLE has the following features:
16
Georg Brandlc21cd7e2008-05-16 17:37:53 +000017* coded in 100% pure Python, using the :mod:`tkinter` GUI toolkit
Georg Brandl8ec7f652007-08-15 14:28:01 +000018
Terry Jan Reedy7cca4e52015-09-24 03:09:38 -040019* cross-platform: works mostly the same on Windows, Unix, and Mac OS X
Georg Brandl8ec7f652007-08-15 14:28:01 +000020
Terry Jan Reedy6741a5a2015-09-23 20:00:22 -040021* Python shell window (interactive interpreter) with colorizing
22 of code input, output, and error messages
23
Terry Jan Reedyeb405892014-12-04 00:55:46 -050024* multi-window text editor with multiple undo, Python colorizing,
Terry Jan Reedy6741a5a2015-09-23 20:00:22 -040025 smart indent, call tips, auto completion, and other features
Georg Brandl8ec7f652007-08-15 14:28:01 +000026
Terry Jan Reedy6741a5a2015-09-23 20:00:22 -040027* search within any window, replace within editor windows, and search
28 through multiple files (grep)
Georg Brandl8ec7f652007-08-15 14:28:01 +000029
Terry Jan Reedy6741a5a2015-09-23 20:00:22 -040030* debugger with persistent breakpoints, stepping, and viewing
31 of global and local namespaces
Georg Brandl8ec7f652007-08-15 14:28:01 +000032
Terry Jan Reedy6741a5a2015-09-23 20:00:22 -040033* configuration, browsers, and other dialogs
Georg Brandl8ec7f652007-08-15 14:28:01 +000034
35Menus
36-----
37
Terry Jan Reedybafef5a2014-12-05 02:42:54 -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 Brandl8ec7f652007-08-15 14:28:01 +000046
Terry Jan Reedyeb405892014-12-04 00:55:46 -050047File menu (Shell and Editor)
48^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Georg Brandl8ec7f652007-08-15 14:28:01 +000049
Terry Jan Reedybafef5a2014-12-05 02:42:54 -050050New File
51 Create a new file editing window.
Georg Brandl8ec7f652007-08-15 14:28:01 +000052
53Open...
Terry Jan Reedybafef5a2014-12-05 02:42:54 -050054 Open an existing file with an Open dialog.
Georg Brandl8ec7f652007-08-15 14:28:01 +000055
Terry Jan Reedyeb405892014-12-04 00:55:46 -050056Recent Files
Terry Jan Reedybafef5a2014-12-05 02:42:54 -050057 Open a list of recent files. Click one to open it.
58
59Open Module...
60 Open an existing module (searches sys.path).
Georg Brandl8ec7f652007-08-15 14:28:01 +000061
62.. index::
63 single: Class browser
64 single: Path browser
65
Terry Jan Reedybafef5a2014-12-05 02:42:54 -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.
Terry Jan Reedyeb405892014-12-04 00:55:46 -050069
Terry Jan Reedybafef5a2014-12-05 02:42:54 -050070Path Browser
71 Show sys.path directories, modules, functions, classes and methods in a
72 tree structure.
Terry Jan Reedyeb405892014-12-04 00:55:46 -050073
Georg Brandl8ec7f652007-08-15 14:28:01 +000074Save
Terry Jan Reedybafef5a2014-12-05 02:42:54 -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 Brandl8ec7f652007-08-15 14:28:01 +000079
80Save As...
Terry Jan Reedybafef5a2014-12-05 02:42:54 -050081 Save the current window with a Save As dialog. The file saved becomes the
82 new associated file for the window.
Georg Brandl8ec7f652007-08-15 14:28:01 +000083
84Save Copy As...
Terry Jan Reedybafef5a2014-12-05 02:42:54 -050085 Save the current window to different file without changing the associated
86 file.
Terry Jan Reedyeb405892014-12-04 00:55:46 -050087
88Print Window
Terry Jan Reedybafef5a2014-12-05 02:42:54 -050089 Print the current window to the default printer.
Georg Brandl8ec7f652007-08-15 14:28:01 +000090
91Close
Terry Jan Reedybafef5a2014-12-05 02:42:54 -050092 Close the current window (ask to save if unsaved).
Georg Brandl8ec7f652007-08-15 14:28:01 +000093
94Exit
Terry Jan Reedybafef5a2014-12-05 02:42:54 -050095 Close all windows and quit IDLE (ask to save unsaved windows).
Georg Brandl8ec7f652007-08-15 14:28:01 +000096
Terry Jan Reedyeb405892014-12-04 00:55:46 -050097Edit menu (Shell and Editor)
98^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Georg Brandl8ec7f652007-08-15 14:28:01 +000099
100Undo
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500101 Undo the last change to the current window. A maximum of 1000 changes may
102 be undone.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000103
104Redo
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500105 Redo the last undone change to the current window.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000106
107Cut
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500108 Copy selection into the system-wide clipboard; then delete the selection.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000109
110Copy
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500111 Copy selection into the system-wide clipboard.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000112
113Paste
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500114 Insert contents of the system-wide clipboard into the current window.
115
116The clipboard functions are also available in context menus.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000117
118Select All
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500119 Select the entire contents of the current window.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000120
121Find...
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500122 Open a search dialog with many options
Georg Brandl8ec7f652007-08-15 14:28:01 +0000123
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500124Find Again
125 Repeat the last search, if there is one.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000126
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500127Find Selection
128 Search for the currently selected string, if there is one.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000129
130Find in Files...
Serhiy Storchaka9a118f12016-04-17 09:37:36 +0300131 Open a file search dialog. Put results in a new output window.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000132
133Replace...
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500134 Open a search-and-replace dialog.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000135
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500136Go to Line
137 Move cursor to the line number requested and make that line visible.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000138
Terry Jan Reedybafef5a2014-12-05 02:42:54 -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.
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500146
147Show call tip
148 After an unclosed parenthesis for a function, open a small window with
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500149 function parameter hints.
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500150
151Show surrounding parens
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500152 Highlight the surrounding parenthesis.
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500153
154Format menu (Editor window only)
155^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
156
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500157Indent Region
158 Shift selected lines right by the indent width (default 4 spaces).
Georg Brandl8ec7f652007-08-15 14:28:01 +0000159
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500160Dedent Region
161 Shift selected lines left by the indent width (default 4 spaces).
Georg Brandl8ec7f652007-08-15 14:28:01 +0000162
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500163Comment Out Region
164 Insert ## in front of selected lines.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000165
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500166Uncomment Region
167 Remove leading # or ## from selected lines.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000168
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500169Tabify Region
170 Turn *leading* stretches of spaces into tabs. (Note: We recommend using
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500171 4 space blocks to indent Python code.)
Georg Brandl8ec7f652007-08-15 14:28:01 +0000172
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500173Untabify Region
174 Turn *all* tabs into the correct number of spaces.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000175
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500176Toggle Tabs
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500177 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 Brandl8ec7f652007-08-15 14:28:01 +0000182
183Format Paragraph
Terry Jan Reedybafef5a2014-12-05 02:42:54 -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 Brandl8ec7f652007-08-15 14:28:01 +0000187
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500188Strip trailing whitespace
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500189 Remove any space characters after the last non-space character of a line.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000190
191.. index::
Georg Brandl8ec7f652007-08-15 14:28:01 +0000192 single: Run script
193
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500194Run menu (Editor window only)
195^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Georg Brandl8ec7f652007-08-15 14:28:01 +0000196
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500197Python Shell
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500198 Open or wake up the Python Shell window.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000199
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500200Check Module
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500201 Check the syntax of the module currently open in the Editor window. If the
Terry Jan Reedybafef5a2014-12-05 02:42:54 -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 Brandl8ec7f652007-08-15 14:28:01 +0000206
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500207Run Module
208 Do Check Module (above). If no error, restart the shell to clean the
Terry Jan Reedycf5bf822015-09-24 01:39:25 -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 Brandl8ec7f652007-08-15 14:28:01 +0000215
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500216Shell menu (Shell window only)
217^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Ned Deilyc859bd22012-10-20 13:23:25 -0700218
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500219View Last Restart
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500220 Scroll the shell window to the last Shell restart.
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500221
222Restart Shell
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500223 Restart the shell to clean the environment.
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500224
Terry Jan Reedy87bcc1d2016-09-12 01:49:55 -0400225Interrupt Execution
226 Stop a running program.
227
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500228Debug menu (Shell window only)
229^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Georg Brandl8ec7f652007-08-15 14:28:01 +0000230
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500231Go to File/Line
232 Look on the current line. with the cursor, and the line above for a filename
233 and line number. If found, open the file if not already open, and show the
234 line. Use this to view source lines referenced in an exception traceback
235 and lines found by Find in Files. Also available in the context menu of
236 the Shell window and Output windows.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000237
238.. index::
Georg Brandl8ec7f652007-08-15 14:28:01 +0000239 single: debugger
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500240 single: stack viewer
241
242Debugger (toggle)
csabella4734c2d2017-04-29 20:44:04 -0400243 When activated, code entered in the Shell or run from an Editor will run
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500244 under the debugger. In the Editor, breakpoints can be set with the context
245 menu. This feature is still incomplete and somewhat experimental.
246
247Stack Viewer
248 Show the stack traceback of the last exception in a tree widget, with
249 access to locals and globals.
250
251Auto-open Stack Viewer
252 Toggle automatically opening the stack viewer on an unhandled exception.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000253
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500254Options menu (Shell and Editor)
255^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Georg Brandl8ec7f652007-08-15 14:28:01 +0000256
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500257Configure IDLE
Terry Jan Reedy1c49ec02015-10-13 22:03:44 -0400258 Open a configuration dialog and change preferences for the following:
259 fonts, indentation, keybindings, text color themes, startup windows and
260 size, additional help sources, and extensions (see below). On OS X,
261 open the configuration dialog by selecting Preferences in the application
262 menu. To use a new built-in color theme (IDLE Dark) with older IDLEs,
263 save it as a new custom theme.
Ned Deilyc859bd22012-10-20 13:23:25 -0700264
Terry Jan Reedy1c49ec02015-10-13 22:03:44 -0400265 Non-default user settings are saved in a .idlerc directory in the user's
266 home directory. Problems caused by bad user configuration files are solved
267 by editing or deleting one or more of the files in .idlerc.
Terry Jan Reedy9e466cf2014-12-04 01:22:41 -0500268
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500269Code Context (toggle)(Editor Window only)
270 Open a pane at the top of the edit window which shows the block context
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500271 of the code which has scrolled above the top of the window.
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500272
Ned Deilyb5daa3d2015-01-17 21:03:41 -0800273Window menu (Shell and Editor)
274^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500275
276Zoom Height
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500277 Toggles the window between normal size and maximum height. The initial size
278 defaults to 40 lines by 80 chars unless changed on the General tab of the
279 Configure IDLE dialog.
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500280
281The rest of this menu lists the names of all open windows; select one to bring
282it to the foreground (deiconifying it if necessary).
283
284Help menu (Shell and Editor)
285^^^^^^^^^^^^^^^^^^^^^^^^^^^^
286
287About IDLE
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500288 Display version, copyright, license, credits, and more.
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500289
290IDLE Help
291 Display a help file for IDLE detailing the menu options, basic editing and
292 navigation, and other tips.
293
294Python Docs
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500295 Access local Python documentation, if installed, or start a web browser
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500296 and open docs.python.org showing the latest Python documentation.
297
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500298Turtle Demo
299 Run the turtledemo module with example python code and turtle drawings.
300
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500301Additional help sources may be added here with the Configure IDLE dialog under
302the General tab.
303
304.. index::
305 single: Cut
306 single: Copy
307 single: Paste
308 single: Set Breakpoint
309 single: Clear Breakpoint
310 single: breakpoints
311
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500312Context Menus
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500313^^^^^^^^^^^^^^^^^^^^^^^^^^
314
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500315Open a context menu by right-clicking in a window (Control-click on OS X).
316Context menus have the standard clipboard functions also on the Edit menu.
Ned Deilyc859bd22012-10-20 13:23:25 -0700317
Andrew Svetlov5018db72012-11-01 22:39:14 +0200318Cut
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500319 Copy selection into the system-wide clipboard; then delete the selection.
Andrew Svetlov5018db72012-11-01 22:39:14 +0200320
321Copy
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500322 Copy selection into the system-wide clipboard.
Andrew Svetlov5018db72012-11-01 22:39:14 +0200323
324Paste
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500325 Insert contents of the system-wide clipboard into the current window.
326
327Editor windows also have breakpoint functions. Lines with a breakpoint set are
328specially marked. Breakpoints only have an effect when running under the
329debugger. Breakpoints for a file are saved in the user's .idlerc directory.
Andrew Svetlov5018db72012-11-01 22:39:14 +0200330
Ned Deilyc859bd22012-10-20 13:23:25 -0700331Set Breakpoint
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500332 Set a breakpoint on the current line.
Ned Deilyc859bd22012-10-20 13:23:25 -0700333
334Clear Breakpoint
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500335 Clear the breakpoint on that line.
Ned Deilyc859bd22012-10-20 13:23:25 -0700336
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500337Shell and Output windows have the following.
Andrew Svetlov5018db72012-11-01 22:39:14 +0200338
Ned Deilyc859bd22012-10-20 13:23:25 -0700339Go to file/line
340 Same as in Debug menu.
341
342
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500343Editing and navigation
344----------------------
345
Serhiy Storchaka9b2e37f2015-09-12 17:47:12 +0300346In this section, 'C' refers to the :kbd:`Control` key on Windows and Unix and
347the :kbd:`Command` key on Mac OSX.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000348
349* :kbd:`Backspace` deletes to the left; :kbd:`Del` deletes to the right
350
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500351* :kbd:`C-Backspace` delete word left; :kbd:`C-Del` delete word to the right
352
Georg Brandl8ec7f652007-08-15 14:28:01 +0000353* Arrow keys and :kbd:`Page Up`/:kbd:`Page Down` to move around
354
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500355* :kbd:`C-LeftArrow` and :kbd:`C-RightArrow` moves by words
356
Georg Brandl8ec7f652007-08-15 14:28:01 +0000357* :kbd:`Home`/:kbd:`End` go to begin/end of line
358
359* :kbd:`C-Home`/:kbd:`C-End` go to begin/end of file
360
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500361* Some useful Emacs bindings are inherited from Tcl/Tk:
362
363 * :kbd:`C-a` beginning of line
364
365 * :kbd:`C-e` end of line
366
367 * :kbd:`C-k` kill line (but doesn't put it in clipboard)
368
369 * :kbd:`C-l` center window around the insertion point
370
csabella4734c2d2017-04-29 20:44:04 -0400371 * :kbd:`C-b` go backward one character without deleting (usually you can
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500372 also use the cursor key for this)
373
374 * :kbd:`C-f` go forward one character without deleting (usually you can
375 also use the cursor key for this)
376
377 * :kbd:`C-p` go up one line (usually you can also use the cursor key for
378 this)
379
380 * :kbd:`C-d` delete next character
381
382Standard keybindings (like :kbd:`C-c` to copy and :kbd:`C-v` to paste)
383may work. Keybindings are selected in the Configure IDLE dialog.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000384
385
386Automatic indentation
387^^^^^^^^^^^^^^^^^^^^^
388
389After a block-opening statement, the next line is indented by 4 spaces (in the
390Python Shell window by one tab). After certain keywords (break, return etc.)
391the next line is dedented. In leading indentation, :kbd:`Backspace` deletes up
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500392to 4 spaces if they are there. :kbd:`Tab` inserts spaces (in the Python
csabella4734c2d2017-04-29 20:44:04 -0400393Shell window one tab), number depends on Indent width. Currently, tabs
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500394are restricted to four spaces due to Tcl/Tk limitations.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000395
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500396See also the indent/dedent region commands in the edit menu.
397
398Completions
399^^^^^^^^^^^
400
401Completions are supplied for functions, classes, and attributes of classes,
402both built-in and user-defined. Completions are also provided for
403filenames.
404
405The AutoCompleteWindow (ACW) will open after a predefined delay (default is
406two seconds) after a '.' or (in a string) an os.sep is typed. If after one
407of those characters (plus zero or more other characters) a tab is typed
408the ACW will open immediately if a possible continuation is found.
409
410If there is only one possible completion for the characters entered, a
411:kbd:`Tab` will supply that completion without opening the ACW.
412
413'Show Completions' will force open a completions window, by default the
414:kbd:`C-space` will open a completions window. In an empty
415string, this will contain the files in the current directory. On a
416blank line, it will contain the built-in and user-defined functions and
csabella4734c2d2017-04-29 20:44:04 -0400417classes in the current namespaces, plus any modules imported. If some
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500418characters have been entered, the ACW will attempt to be more specific.
419
420If a string of characters is typed, the ACW selection will jump to the
421entry most closely matching those characters. Entering a :kbd:`tab` will
422cause the longest non-ambiguous match to be entered in the Editor window or
423Shell. Two :kbd:`tab` in a row will supply the current ACW selection, as
424will return or a double click. Cursor keys, Page Up/Down, mouse selection,
425and the scroll wheel all operate on the ACW.
426
427"Hidden" attributes can be accessed by typing the beginning of hidden
428name after a '.', e.g. '_'. This allows access to modules with
429``__all__`` set, or to class-private attributes.
430
431Completions and the 'Expand Word' facility can save a lot of typing!
432
433Completions are currently limited to those in the namespaces. Names in
434an Editor window which are not via ``__main__`` and :data:`sys.modules` will
435not be found. Run the module once with your imports to correct this situation.
436Note that IDLE itself places quite a few modules in sys.modules, so
437much can be found by default, e.g. the re module.
438
439If you don't like the ACW popping up unbidden, simply make the delay
Terry Jan Reedy958a9c72015-09-29 01:55:50 -0400440longer or disable the extension.
441
442Calltips
443^^^^^^^^
444
445A calltip is shown when one types :kbd:`(` after the name of an *acccessible*
446function. A name expression may include dots and subscripts. A calltip
447remains until it is clicked, the cursor is moved out of the argument area,
448or :kbd:`)` is typed. When the cursor is in the argument part of a definition,
449the menu or shortcut display a calltip.
450
451A calltip consists of the function signature and the first line of the
452docstring. For builtins without an accessible signature, the calltip
453consists of all lines up the fifth line or the first blank line. These
454details may change.
455
456The set of *accessible* functions depends on what modules have been imported
457into the user process, including those imported by Idle itself,
458and what definitions have been run, all since the last restart.
459
460For example, restart the Shell and enter ``itertools.count(``. A calltip
461appears because Idle imports itertools into the user process for its own use.
462(This could change.) Enter ``turtle.write(`` and nothing appears. Idle does
463not import turtle. The menu or shortcut do nothing either. Enter
464``import turtle`` and then ``turtle.write(`` will work.
465
466In an editor, import statements have no effect until one runs the file. One
467might want to run a file after writing the import statements at the top,
468or immediately run an existing file before editing.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000469
470Python Shell window
471^^^^^^^^^^^^^^^^^^^
472
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500473* :kbd:`C-c` interrupts executing command
Georg Brandl8ec7f652007-08-15 14:28:01 +0000474
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500475* :kbd:`C-d` sends end-of-file; closes window if typed at a ``>>>`` prompt
Georg Brandl8ec7f652007-08-15 14:28:01 +0000476
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500477* :kbd:`Alt-/` (Expand word) is also useful to reduce typing
Georg Brandl8ec7f652007-08-15 14:28:01 +0000478
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500479 Command history
Georg Brandl8ec7f652007-08-15 14:28:01 +0000480
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500481 * :kbd:`Alt-p` retrieves previous command matching what you have typed. On
482 OS X use :kbd:`C-p`.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000483
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500484 * :kbd:`Alt-n` retrieves next. On OS X use :kbd:`C-n`.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000485
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500486 * :kbd:`Return` while on any previous command retrieves that command
Georg Brandl8ec7f652007-08-15 14:28:01 +0000487
488
Terry Jan Reedyf56f8d12015-09-24 23:13:43 -0400489Text colors
490^^^^^^^^^^^
Georg Brandl8ec7f652007-08-15 14:28:01 +0000491
Terry Jan Reedyf56f8d12015-09-24 23:13:43 -0400492Idle defaults to black on white text, but colors text with special meanings.
493For the shell, these are shell output, shell error, user output, and
494user error. For Python code, at the shell prompt or in an editor, these are
495keywords, builtin class and function names, names following ``class`` and
496``def``, strings, and comments. For any text window, these are the cursor (when
497present), found text (when possible), and selected text.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000498
Terry Jan Reedyf56f8d12015-09-24 23:13:43 -0400499Text coloring is done in the background, so uncolorized text is occasionally
500visible. To change the color scheme, use the Configure IDLE dialog
501Highlighting tab. The marking of debugger breakpoint lines in the editor and
502text in popups and dialogs is not user-configurable.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000503
504
Terry Jan Reedy7cca4e52015-09-24 03:09:38 -0400505Startup and code execution
506--------------------------
Georg Brandl09827eb2009-03-15 21:51:48 +0000507
508Upon startup with the ``-s`` option, IDLE will execute the file referenced by
509the environment variables :envvar:`IDLESTARTUP` or :envvar:`PYTHONSTARTUP`.
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500510IDLE first checks for ``IDLESTARTUP``; if ``IDLESTARTUP`` is present the file
511referenced is run. If ``IDLESTARTUP`` is not present, IDLE checks for
Georg Brandl09827eb2009-03-15 21:51:48 +0000512``PYTHONSTARTUP``. Files referenced by these environment variables are
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500513convenient places to store functions that are used frequently from the IDLE
Georg Brandl09827eb2009-03-15 21:51:48 +0000514shell, or for executing import statements to import common modules.
515
516In addition, ``Tk`` also loads a startup file if it is present. Note that the
517Tk file is loaded unconditionally. This additional file is ``.Idle.py`` and is
518looked for in the user's home directory. Statements in this file will be
Terry Jan Reedybafef5a2014-12-05 02:42:54 -0500519executed in the Tk namespace, so this file is not useful for importing
520functions to be used from IDLE's Python shell.
Georg Brandl09827eb2009-03-15 21:51:48 +0000521
522
Georg Brandl8ec7f652007-08-15 14:28:01 +0000523Command line usage
524^^^^^^^^^^^^^^^^^^
525
Martin Panter8f1dd222016-07-26 11:18:21 +0200526.. code-block:: none
Georg Brandl8ec7f652007-08-15 14:28:01 +0000527
Terry Jan Reedyc7025c62015-09-23 03:52:18 -0400528 idle.py [-c command] [-d] [-e] [-h] [-i] [-r file] [-s] [-t title] [-] [arg] ...
Georg Brandl8ec7f652007-08-15 14:28:01 +0000529
Terry Jan Reedyc7025c62015-09-23 03:52:18 -0400530 -c command run command in the shell window
531 -d enable debugger and open shell window
532 -e open editor window
Terry Jan Reedy580ca652016-08-30 16:57:53 -0400533 -h print help message with legal combinations and exit
Terry Jan Reedyc7025c62015-09-23 03:52:18 -0400534 -i open shell window
535 -r file run file in shell window
536 -s run $IDLESTARTUP or $PYTHONSTARTUP first, in shell window
Georg Brandl8ec7f652007-08-15 14:28:01 +0000537 -t title set title of shell window
Terry Jan Reedyc7025c62015-09-23 03:52:18 -0400538 - run stdin in shell (- must be last option before args)
Georg Brandl8ec7f652007-08-15 14:28:01 +0000539
540If there are arguments:
541
Terry Jan Reedyc7025c62015-09-23 03:52:18 -0400542* If ``-``, ``-c``, or ``r`` is used, all arguments are placed in
543 ``sys.argv[1:...]`` and ``sys.argv[0]`` is set to ``''``, ``'-c'``,
544 or ``'-r'``. No editor window is opened, even if that is the default
545 set in the Options dialog.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000546
Terry Jan Reedyc7025c62015-09-23 03:52:18 -0400547* Otherwise, arguments are files opened for editing and
548 ``sys.argv`` reflects the arguments passed to IDLE itself.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000549
Georg Brandl8ec7f652007-08-15 14:28:01 +0000550
Terry Jan Reedy7cca4e52015-09-24 03:09:38 -0400551IDLE-console differences
552^^^^^^^^^^^^^^^^^^^^^^^^
553
554As much as possible, the result of executing Python code with IDLE is the
555same as executing the same code in a console window. However, the different
csabella4734c2d2017-04-29 20:44:04 -0400556interface and operation occasionally affect visible results. For instance,
Terry Jan Reedy7d03c842016-05-02 18:17:19 -0400557``sys.modules`` starts with more entries.
Terry Jan Reedy7cca4e52015-09-24 03:09:38 -0400558
Terry Jan Reedy7d03c842016-05-02 18:17:19 -0400559IDLE also replaces ``sys.stdin``, ``sys.stdout``, and ``sys.stderr`` with
560objects that get input from and send output to the Shell window.
561When this window has the focus, it controls the keyboard and screen.
562This is normally transparent, but functions that directly access the keyboard
563and screen will not work. If ``sys`` is reset with ``reload(sys)``,
564IDLE's changes are lost and things like ``input``, ``raw_input``, and
565``print`` will not work correctly.
Terry Jan Reedy7cca4e52015-09-24 03:09:38 -0400566
567With IDLE's Shell, one enters, edits, and recalls complete statements.
Terry Jan Reedy558c0de2016-08-25 01:21:54 -0400568Some consoles only work with a single physical line at a time. IDLE uses
569``exec`` to run each statement. As a result, ``'__builtins__'`` is always
570defined for each statement.
Terry Jan Reedy7cca4e52015-09-24 03:09:38 -0400571
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500572Running without a subprocess
573^^^^^^^^^^^^^^^^^^^^^^^^^^^^
574
Terry Jan Reedy7cca4e52015-09-24 03:09:38 -0400575By default, IDLE executes user code in a separate subprocess via a socket,
Terry Jan Reedy6741a5a2015-09-23 20:00:22 -0400576which uses the internal loopback interface. This connection is not
577externally visible and no data is sent to or received from the Internet.
578If firewall software complains anyway, you can ignore it.
579
580If the attempt to make the socket connection fails, Idle will notify you.
581Such failures are sometimes transient, but if persistent, the problem
csabella4734c2d2017-04-29 20:44:04 -0400582may be either a firewall blocking the connection or misconfiguration of
Terry Jan Reedy6741a5a2015-09-23 20:00:22 -0400583a particular system. Until the problem is fixed, one can run Idle with
584the -n command line switch.
585
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500586If IDLE is started with the -n command line switch it will run in a
587single process and will not create the subprocess which runs the RPC
588Python execution server. This can be useful if Python cannot create
589the subprocess or the RPC socket interface on your platform. However,
590in this mode user code is not isolated from IDLE itself. Also, the
591environment is not restarted when Run/Run Module (F5) is selected. If
592your code has been modified, you must reload() the affected modules and
593re-import any specific items (e.g. from foo import baz) if the changes
594are to take effect. For these reasons, it is preferable to run IDLE
595with the default subprocess if at all possible.
596
597.. deprecated:: 3.4
598
599
Terry Jan Reedy9e466cf2014-12-04 01:22:41 -0500600Help and preferences
601--------------------
602
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500603Additional help sources
Terry Jan Reedy9e466cf2014-12-04 01:22:41 -0500604^^^^^^^^^^^^^^^^^^^^^^^
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500605
606IDLE includes a help menu entry called "Python Docs" that will open the
607extensive sources of help, including tutorials, available at docs.python.org.
608Selected URLs can be added or removed from the help menu at any time using the
609Configure IDLE dialog. See the IDLE help option in the help menu of IDLE for
610more information.
611
612
Terry Jan Reedy9e466cf2014-12-04 01:22:41 -0500613Setting preferences
614^^^^^^^^^^^^^^^^^^^
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500615
616The font preferences, highlighting, keys, and general preferences can be
Terry Jan Reedy9e466cf2014-12-04 01:22:41 -0500617changed via Configure IDLE on the Option menu. Keys can be user defined;
csabella4734c2d2017-04-29 20:44:04 -0400618IDLE ships with four built-in key sets. In addition, a user can create a
Terry Jan Reedy9e466cf2014-12-04 01:22:41 -0500619custom key set in the Configure IDLE dialog under the keys tab.
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500620
621
622Extensions
Terry Jan Reedy9e466cf2014-12-04 01:22:41 -0500623^^^^^^^^^^
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500624
csabella4734c2d2017-04-29 20:44:04 -0400625IDLE contains an extension facility. Preferences for extensions can be
Terry Jan Reedy9e466cf2014-12-04 01:22:41 -0500626changed with Configure Extensions. See the beginning of config-extensions.def
627in the idlelib directory for further information. The default extensions
628are currently:
Terry Jan Reedyeb405892014-12-04 00:55:46 -0500629
630* FormatParagraph
631
632* AutoExpand
633
634* ZoomHeight
635
636* ScriptBinding
637
638* CallTips
639
640* ParenMatch
641
642* AutoComplete
643
644* CodeContext
Georg Brandl8ec7f652007-08-15 14:28:01 +0000645
Terry Jan Reedy9e466cf2014-12-04 01:22:41 -0500646* RstripExtension