blob: c5015bf30cfb78fbdd4e37b7e036891d834e286f [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 Reedyff702892017-09-15 13:05:28 -0400193 Remove trailing space and other whitespace characters after the last
194 non-whitespace character of a line by applying str.rstrip to each line,
195 including lines within multiline strings.
Georg Brandl116aa622007-08-15 14:28:22 +0000196
197.. index::
Georg Brandl116aa622007-08-15 14:28:22 +0000198 single: Run script
199
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200200Run menu (Editor window only)
201^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +0000202
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200203Python Shell
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500204 Open or wake up the Python Shell window.
Georg Brandl116aa622007-08-15 14:28:22 +0000205
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500206Check Module
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200207 Check the syntax of the module currently open in the Editor window. If the
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500208 module has not been saved IDLE will either prompt the user to save or
209 autosave, as selected in the General tab of the Idle Settings dialog. If
210 there is a syntax error, the approximate location is indicated in the
211 Editor window.
Georg Brandl116aa622007-08-15 14:28:22 +0000212
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500213Run Module
214 Do Check Module (above). If no error, restart the shell to clean the
Terry Jan Reedy8b5a9812015-09-24 01:39:30 -0400215 environment, then execute the module. Output is displayed in the Shell
216 window. Note that output requires use of ``print`` or ``write``.
217 When execution is complete, the Shell retains focus and displays a prompt.
218 At this point, one may interactively explore the result of execution.
219 This is similar to executing a file with ``python -i file`` at a command
220 line.
Georg Brandl116aa622007-08-15 14:28:22 +0000221
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200222Shell menu (Shell window only)
223^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Ned Deily2778d0d2012-10-20 13:25:34 -0700224
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200225View Last Restart
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500226 Scroll the shell window to the last Shell restart.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200227
228Restart Shell
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500229 Restart the shell to clean the environment.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200230
Terry Jan Reedy4b736762016-09-12 01:50:03 -0400231Interrupt Execution
232 Stop a running program.
233
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200234Debug menu (Shell window only)
235^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +0000236
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500237Go to File/Line
238 Look on the current line. with the cursor, and the line above for a filename
239 and line number. If found, open the file if not already open, and show the
240 line. Use this to view source lines referenced in an exception traceback
241 and lines found by Find in Files. Also available in the context menu of
242 the Shell window and Output windows.
Georg Brandl116aa622007-08-15 14:28:22 +0000243
244.. index::
Georg Brandl116aa622007-08-15 14:28:22 +0000245 single: debugger
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500246 single: stack viewer
247
248Debugger (toggle)
csabella9dc2b382017-04-29 18:28:36 -0400249 When activated, code entered in the Shell or run from an Editor will run
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500250 under the debugger. In the Editor, breakpoints can be set with the context
251 menu. This feature is still incomplete and somewhat experimental.
252
253Stack Viewer
254 Show the stack traceback of the last exception in a tree widget, with
255 access to locals and globals.
256
257Auto-open Stack Viewer
258 Toggle automatically opening the stack viewer on an unhandled exception.
Georg Brandl116aa622007-08-15 14:28:22 +0000259
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200260Options menu (Shell and Editor)
261^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +0000262
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200263Configure IDLE
Terry Jan Reedy93f35422015-10-13 22:03:51 -0400264 Open a configuration dialog and change preferences for the following:
265 fonts, indentation, keybindings, text color themes, startup windows and
266 size, additional help sources, and extensions (see below). On OS X,
267 open the configuration dialog by selecting Preferences in the application
268 menu. To use a new built-in color theme (IDLE Dark) with older IDLEs,
269 save it as a new custom theme.
Ned Deily2778d0d2012-10-20 13:25:34 -0700270
Terry Jan Reedy93f35422015-10-13 22:03:51 -0400271 Non-default user settings are saved in a .idlerc directory in the user's
272 home directory. Problems caused by bad user configuration files are solved
273 by editing or deleting one or more of the files in .idlerc.
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500274
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200275Code Context (toggle)(Editor Window only)
276 Open a pane at the top of the edit window which shows the block context
Terry Jan Reedyaf4b0132018-06-10 15:48:41 -0400277 of the code which has scrolled above the top of the window. Clicking a
278 line in this pane exposes that line at the top of the editor.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200279
Ned Deilyccb416f2015-01-17 21:06:27 -0800280Window menu (Shell and Editor)
281^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200282
283Zoom Height
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500284 Toggles the window between normal size and maximum height. The initial size
285 defaults to 40 lines by 80 chars unless changed on the General tab of the
286 Configure IDLE dialog.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200287
288The rest of this menu lists the names of all open windows; select one to bring
289it to the foreground (deiconifying it if necessary).
290
291Help menu (Shell and Editor)
292^^^^^^^^^^^^^^^^^^^^^^^^^^^^
293
294About IDLE
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500295 Display version, copyright, license, credits, and more.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200296
297IDLE Help
Terry Jan Reedy18032632018-10-28 16:21:18 -0400298 Display this IDLE document, detailing the menu options, basic editing and
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200299 navigation, and other tips.
300
301Python Docs
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500302 Access local Python documentation, if installed, or start a web browser
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200303 and open docs.python.org showing the latest Python documentation.
304
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500305Turtle Demo
Andrés Delfino271818f2018-09-14 14:13:09 -0300306 Run the turtledemo module with example Python code and turtle drawings.
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500307
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200308Additional help sources may be added here with the Configure IDLE dialog under
Terry Jan Reedy18032632018-10-28 16:21:18 -0400309the General tab. See the "Help sources" subsection below for more
310on Help menu choices.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200311
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500312.. index::
313 single: Cut
314 single: Copy
315 single: Paste
316 single: Set Breakpoint
317 single: Clear Breakpoint
318 single: breakpoints
319
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500320Context Menus
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200321^^^^^^^^^^^^^^^^^^^^^^^^^^
322
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500323Open a context menu by right-clicking in a window (Control-click on OS X).
324Context menus have the standard clipboard functions also on the Edit menu.
Ned Deily2778d0d2012-10-20 13:25:34 -0700325
Andrew Svetlovd1837672012-11-01 22:41:19 +0200326Cut
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500327 Copy selection into the system-wide clipboard; then delete the selection.
Andrew Svetlovd1837672012-11-01 22:41:19 +0200328
329Copy
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500330 Copy selection into the system-wide clipboard.
Andrew Svetlovd1837672012-11-01 22:41:19 +0200331
332Paste
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500333 Insert contents of the system-wide clipboard into the current window.
334
335Editor windows also have breakpoint functions. Lines with a breakpoint set are
336specially marked. Breakpoints only have an effect when running under the
337debugger. Breakpoints for a file are saved in the user's .idlerc directory.
Andrew Svetlovd1837672012-11-01 22:41:19 +0200338
Ned Deily2778d0d2012-10-20 13:25:34 -0700339Set Breakpoint
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500340 Set a breakpoint on the current line.
Ned Deily2778d0d2012-10-20 13:25:34 -0700341
342Clear Breakpoint
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500343 Clear the breakpoint on that line.
Ned Deily2778d0d2012-10-20 13:25:34 -0700344
Terry Jan Reedy68d6dc02018-10-28 12:44:44 -0400345Shell and Output windows also have the following.
Andrew Svetlovd1837672012-11-01 22:41:19 +0200346
Ned Deily2778d0d2012-10-20 13:25:34 -0700347Go to file/line
348 Same as in Debug menu.
349
Terry Jan Reedy68d6dc02018-10-28 12:44:44 -0400350The Shell window also has an output squeezing facility explained in the
351the *Python Shell window* subsection below.
352
353Squeeze
354 If the cursor is over an output line, squeeze all the output between
355 the code above and the prompt below down to a 'Squeezed text' label.
356
Ned Deily2778d0d2012-10-20 13:25:34 -0700357
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200358Editing and navigation
359----------------------
Georg Brandl116aa622007-08-15 14:28:22 +0000360
Terry Jan Reedyea9c8bd2018-10-28 20:42:18 -0400361Editor windows
362^^^^^^^^^^^^^^
363
364IDLE may open editor windows when it starts, depending on settings
365and how you start IDLE. Thereafter, use the File menu. There can be only
366one open editor window for a given file.
367
368The title bar contains the name of the file, the full path, and the version
369of Python and IDLE running the window. The status bar contains the line
370number ('Ln') and column number ('Col'). Line numbers start with 1;
371column numbers with 0.
372
373IDLE assumes that files with a known .py* extension contain Python code
374and that other files do not. Run Python code with the Run menu.
375
376Key bindings
377^^^^^^^^^^^^
378
Serhiy Storchaka0424eaf2015-09-12 17:45:25 +0300379In this section, 'C' refers to the :kbd:`Control` key on Windows and Unix and
380the :kbd:`Command` key on Mac OSX.
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500381
Georg Brandl116aa622007-08-15 14:28:22 +0000382* :kbd:`Backspace` deletes to the left; :kbd:`Del` deletes to the right
383
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200384* :kbd:`C-Backspace` delete word left; :kbd:`C-Del` delete word to the right
385
Georg Brandl116aa622007-08-15 14:28:22 +0000386* Arrow keys and :kbd:`Page Up`/:kbd:`Page Down` to move around
387
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200388* :kbd:`C-LeftArrow` and :kbd:`C-RightArrow` moves by words
389
Georg Brandl116aa622007-08-15 14:28:22 +0000390* :kbd:`Home`/:kbd:`End` go to begin/end of line
391
392* :kbd:`C-Home`/:kbd:`C-End` go to begin/end of file
393
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200394* Some useful Emacs bindings are inherited from Tcl/Tk:
395
396 * :kbd:`C-a` beginning of line
397
398 * :kbd:`C-e` end of line
399
400 * :kbd:`C-k` kill line (but doesn't put it in clipboard)
401
402 * :kbd:`C-l` center window around the insertion point
403
csabella9dc2b382017-04-29 18:28:36 -0400404 * :kbd:`C-b` go backward one character without deleting (usually you can
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200405 also use the cursor key for this)
406
407 * :kbd:`C-f` go forward one character without deleting (usually you can
408 also use the cursor key for this)
409
410 * :kbd:`C-p` go up one line (usually you can also use the cursor key for
411 this)
412
413 * :kbd:`C-d` delete next character
414
415Standard keybindings (like :kbd:`C-c` to copy and :kbd:`C-v` to paste)
416may work. Keybindings are selected in the Configure IDLE dialog.
Georg Brandl116aa622007-08-15 14:28:22 +0000417
Georg Brandl116aa622007-08-15 14:28:22 +0000418Automatic indentation
419^^^^^^^^^^^^^^^^^^^^^
420
421After a block-opening statement, the next line is indented by 4 spaces (in the
422Python Shell window by one tab). After certain keywords (break, return etc.)
423the next line is dedented. In leading indentation, :kbd:`Backspace` deletes up
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200424to 4 spaces if they are there. :kbd:`Tab` inserts spaces (in the Python
csabella9dc2b382017-04-29 18:28:36 -0400425Shell window one tab), number depends on Indent width. Currently, tabs
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200426are restricted to four spaces due to Tcl/Tk limitations.
Georg Brandl116aa622007-08-15 14:28:22 +0000427
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200428See also the indent/dedent region commands in the edit menu.
429
430Completions
431^^^^^^^^^^^
432
433Completions are supplied for functions, classes, and attributes of classes,
434both built-in and user-defined. Completions are also provided for
435filenames.
436
437The AutoCompleteWindow (ACW) will open after a predefined delay (default is
438two seconds) after a '.' or (in a string) an os.sep is typed. If after one
439of those characters (plus zero or more other characters) a tab is typed
440the ACW will open immediately if a possible continuation is found.
441
442If there is only one possible completion for the characters entered, a
443:kbd:`Tab` will supply that completion without opening the ACW.
444
445'Show Completions' will force open a completions window, by default the
446:kbd:`C-space` will open a completions window. In an empty
447string, this will contain the files in the current directory. On a
448blank line, it will contain the built-in and user-defined functions and
csabella9dc2b382017-04-29 18:28:36 -0400449classes in the current namespaces, plus any modules imported. If some
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200450characters have been entered, the ACW will attempt to be more specific.
451
452If a string of characters is typed, the ACW selection will jump to the
453entry most closely matching those characters. Entering a :kbd:`tab` will
454cause the longest non-ambiguous match to be entered in the Editor window or
455Shell. Two :kbd:`tab` in a row will supply the current ACW selection, as
456will return or a double click. Cursor keys, Page Up/Down, mouse selection,
457and the scroll wheel all operate on the ACW.
458
459"Hidden" attributes can be accessed by typing the beginning of hidden
460name after a '.', e.g. '_'. This allows access to modules with
461``__all__`` set, or to class-private attributes.
462
463Completions and the 'Expand Word' facility can save a lot of typing!
464
465Completions are currently limited to those in the namespaces. Names in
466an Editor window which are not via ``__main__`` and :data:`sys.modules` will
467not be found. Run the module once with your imports to correct this situation.
468Note that IDLE itself places quite a few modules in sys.modules, so
469much can be found by default, e.g. the re module.
470
471If you don't like the ACW popping up unbidden, simply make the delay
Terry Jan Reedy37f81352015-09-29 01:55:57 -0400472longer or disable the extension.
473
474Calltips
475^^^^^^^^
476
Alex Gaynor1cf2a802017-02-28 22:26:56 -0500477A calltip is shown when one types :kbd:`(` after the name of an *accessible*
Terry Jan Reedy37f81352015-09-29 01:55:57 -0400478function. A name expression may include dots and subscripts. A calltip
479remains until it is clicked, the cursor is moved out of the argument area,
480or :kbd:`)` is typed. When the cursor is in the argument part of a definition,
481the menu or shortcut display a calltip.
482
483A calltip consists of the function signature and the first line of the
484docstring. For builtins without an accessible signature, the calltip
485consists of all lines up the fifth line or the first blank line. These
486details may change.
487
488The set of *accessible* functions depends on what modules have been imported
489into the user process, including those imported by Idle itself,
490and what definitions have been run, all since the last restart.
491
492For example, restart the Shell and enter ``itertools.count(``. A calltip
493appears because Idle imports itertools into the user process for its own use.
494(This could change.) Enter ``turtle.write(`` and nothing appears. Idle does
495not import turtle. The menu or shortcut do nothing either. Enter
496``import turtle`` and then ``turtle.write(`` will work.
497
498In an editor, import statements have no effect until one runs the file. One
499might want to run a file after writing the import statements at the top,
500or immediately run an existing file before editing.
Georg Brandl116aa622007-08-15 14:28:22 +0000501
502Python Shell window
503^^^^^^^^^^^^^^^^^^^
504
Terry Jan Reedy68d6dc02018-10-28 12:44:44 -0400505The editing features described above work when entering code interactively.
506IDLE's Shell window also responds to the following keys.
507
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200508* :kbd:`C-c` interrupts executing command
Georg Brandl116aa622007-08-15 14:28:22 +0000509
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200510* :kbd:`C-d` sends end-of-file; closes window if typed at a ``>>>`` prompt
Georg Brandl116aa622007-08-15 14:28:22 +0000511
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200512* :kbd:`Alt-/` (Expand word) is also useful to reduce typing
Georg Brandl116aa622007-08-15 14:28:22 +0000513
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200514 Command history
Georg Brandl116aa622007-08-15 14:28:22 +0000515
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200516 * :kbd:`Alt-p` retrieves previous command matching what you have typed. On
517 OS X use :kbd:`C-p`.
Georg Brandl116aa622007-08-15 14:28:22 +0000518
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200519 * :kbd:`Alt-n` retrieves next. On OS X use :kbd:`C-n`.
Georg Brandl116aa622007-08-15 14:28:22 +0000520
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200521 * :kbd:`Return` while on any previous command retrieves that command
Georg Brandl116aa622007-08-15 14:28:22 +0000522
Terry Jan Reedy68d6dc02018-10-28 12:44:44 -0400523Shell has a special facility for squeezing output lines down to a
524'Squeezed text' label. This is done automatically for output over N lines
525(N = 50 by default). N can be changed in the PyShell section of the General
526page of the Settings dialog. Output with fewer lines can be squeezed by
527right clicking on the output. This can be useful for extra long lines.
528
529Squeezed output is expanded in place by double-clicking the label.
530It can also be sent to the clipboard or a separate view window by
531right-clicking the label.
Georg Brandl116aa622007-08-15 14:28:22 +0000532
Terry Jan Reedyf660ce22015-09-24 23:13:49 -0400533Text colors
534^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +0000535
Terry Jan Reedyf660ce22015-09-24 23:13:49 -0400536Idle defaults to black on white text, but colors text with special meanings.
537For the shell, these are shell output, shell error, user output, and
538user error. For Python code, at the shell prompt or in an editor, these are
539keywords, builtin class and function names, names following ``class`` and
540``def``, strings, and comments. For any text window, these are the cursor (when
541present), found text (when possible), and selected text.
Georg Brandl116aa622007-08-15 14:28:22 +0000542
Terry Jan Reedyf660ce22015-09-24 23:13:49 -0400543Text coloring is done in the background, so uncolorized text is occasionally
544visible. To change the color scheme, use the Configure IDLE dialog
545Highlighting tab. The marking of debugger breakpoint lines in the editor and
546text in popups and dialogs is not user-configurable.
Georg Brandl116aa622007-08-15 14:28:22 +0000547
548
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400549Startup and code execution
550--------------------------
Benjamin Petersonf07d0022009-03-21 17:31:58 +0000551
552Upon startup with the ``-s`` option, IDLE will execute the file referenced by
553the environment variables :envvar:`IDLESTARTUP` or :envvar:`PYTHONSTARTUP`.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200554IDLE first checks for ``IDLESTARTUP``; if ``IDLESTARTUP`` is present the file
555referenced is run. If ``IDLESTARTUP`` is not present, IDLE checks for
Benjamin Petersonf07d0022009-03-21 17:31:58 +0000556``PYTHONSTARTUP``. Files referenced by these environment variables are
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200557convenient places to store functions that are used frequently from the IDLE
Benjamin Petersonf07d0022009-03-21 17:31:58 +0000558shell, or for executing import statements to import common modules.
559
560In addition, ``Tk`` also loads a startup file if it is present. Note that the
561Tk file is loaded unconditionally. This additional file is ``.Idle.py`` and is
562looked for in the user's home directory. Statements in this file will be
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500563executed in the Tk namespace, so this file is not useful for importing
564functions to be used from IDLE's Python shell.
Benjamin Petersonf07d0022009-03-21 17:31:58 +0000565
Georg Brandl116aa622007-08-15 14:28:22 +0000566Command line usage
567^^^^^^^^^^^^^^^^^^
568
Martin Panter1050d2d2016-07-26 11:18:21 +0200569.. code-block:: none
Georg Brandl116aa622007-08-15 14:28:22 +0000570
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400571 idle.py [-c command] [-d] [-e] [-h] [-i] [-r file] [-s] [-t title] [-] [arg] ...
Georg Brandl116aa622007-08-15 14:28:22 +0000572
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400573 -c command run command in the shell window
574 -d enable debugger and open shell window
575 -e open editor window
Terry Jan Reedy3399e1e2016-08-30 16:58:01 -0400576 -h print help message with legal combinations and exit
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400577 -i open shell window
578 -r file run file in shell window
579 -s run $IDLESTARTUP or $PYTHONSTARTUP first, in shell window
Georg Brandl116aa622007-08-15 14:28:22 +0000580 -t title set title of shell window
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400581 - run stdin in shell (- must be last option before args)
Georg Brandl116aa622007-08-15 14:28:22 +0000582
583If there are arguments:
584
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400585* If ``-``, ``-c``, or ``r`` is used, all arguments are placed in
586 ``sys.argv[1:...]`` and ``sys.argv[0]`` is set to ``''``, ``'-c'``,
587 or ``'-r'``. No editor window is opened, even if that is the default
588 set in the Options dialog.
Georg Brandl116aa622007-08-15 14:28:22 +0000589
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400590* Otherwise, arguments are files opened for editing and
591 ``sys.argv`` reflects the arguments passed to IDLE itself.
Georg Brandl116aa622007-08-15 14:28:22 +0000592
terryjreedy188aedf2017-06-13 21:32:16 -0400593Startup failure
594^^^^^^^^^^^^^^^
595
596IDLE uses a socket to communicate between the IDLE GUI process and the user
597code execution process. A connection must be established whenever the Shell
598starts or restarts. (The latter is indicated by a divider line that says
599'RESTART'). If the user process fails to connect to the GUI process, it
600displays a ``Tk`` error box with a 'cannot connect' message that directs the
601user here. It then exits.
602
603A common cause of failure is a user-written file with the same name as a
604standard library module, such as *random.py* and *tkinter.py*. When such a
605file is located in the same directory as a file that is about to be run,
606IDLE cannot import the stdlib file. The current fix is to rename the
607user file.
608
609Though less common than in the past, an antivirus or firewall program may
610stop the connection. If the program cannot be taught to allow the
611connection, then it must be turned off for IDLE to work. It is safe to
612allow this internal connection because no data is visible on external
613ports. A similar problem is a network mis-configuration that blocks
614connections.
615
616Python installation issues occasionally stop IDLE: multiple versions can
617clash, or a single installation might need admin access. If one undo the
618clash, or cannot or does not want to run as admin, it might be easiest to
619completely remove Python and start over.
620
621A zombie pythonw.exe process could be a problem. On Windows, use Task
622Manager to detect and stop one. Sometimes a restart initiated by a program
623crash or Keyboard Interrupt (control-C) may fail to connect. Dismissing
624the error box or Restart Shell on the Shell menu may fix a temporary problem.
625
626When IDLE first starts, it attempts to read user configuration files in
627~/.idlerc/ (~ is one's home directory). If there is a problem, an error
628message should be displayed. Leaving aside random disk glitches, this can
629be prevented by never editing the files by hand, using the configuration
630dialog, under Options, instead Options. Once it happens, the solution may
631be to delete one or more of the configuration files.
632
633If IDLE quits with no message, and it was not started from a console, try
634starting from a console (``python -m idlelib)`` and see if a message appears.
635
Terry Jan Reedy5e790902018-11-05 21:30:32 -0500636Running user code
637^^^^^^^^^^^^^^^^^
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400638
Terry Jan Reedy98758bc2017-09-12 09:05:16 -0400639With rare exceptions, the result of executing Python code with IDLE is
Terry Jan Reedy5e790902018-11-05 21:30:32 -0500640intended to be the same as executing the same code by the default method,
641directly with Python in a text-mode system console or terminal window.
Terry Jan Reedy98758bc2017-09-12 09:05:16 -0400642However, the different interface and operation occasionally affect
Terry Jan Reedy5e790902018-11-05 21:30:32 -0500643visible results. For instance, ``sys.modules`` starts with more entries,
644and ``threading.activeCount()`` returns 2 instead of 1.
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400645
Terry Jan Reedy5e790902018-11-05 21:30:32 -0500646By default, IDLE runs user code in a separate OS process rather than in
647the user interface process that runs the shell and editor. In the execution
648process, it replaces ``sys.stdin``, ``sys.stdout``, and ``sys.stderr``
649with objects that get input from and send output to the Shell window.
650The original values stored in ``sys.__stdin__``, ``sys.__stdout__``, and
651``sys.__stderr__`` are not touched, but may be ``None``.
652
Terry Jan Reedy98758bc2017-09-12 09:05:16 -0400653When Shell has the focus, it controls the keyboard and screen. This is
654normally transparent, but functions that directly access the keyboard
Terry Jan Reedy5e790902018-11-05 21:30:32 -0500655and screen will not work. These include system-specific functions that
656determine whether a key has been pressed and if so, which.
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400657
Terry Jan Reedy5e790902018-11-05 21:30:32 -0500658IDLE's standard stream replacements are not inherited by subprocesses
659created in the execution process, whether directly by user code or by modules
660such as multiprocessing. If such subprocess use ``input`` from sys.stdin
661or ``print`` or ``write`` to sys.stdout or sys.stderr,
662IDLE should be started in a command line window. The secondary subprocess
663will then be attached to that window for input and output.
664
665If ``sys`` is reset by user code, such as with ``importlib.reload(sys)``,
666IDLE's changes are lost and input from the keyboard and output to the screen
667will not work correctly.
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400668
Terry Jan Reedy98758bc2017-09-12 09:05:16 -0400669Developing tkinter applications
670^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
671
672IDLE is intentionally different from standard Python in order to
673facilitate development of tkinter programs. Enter ``import tkinter as tk;
674root = tk.Tk()`` in standard Python and nothing appears. Enter the same
675in IDLE and a tk window appears. In standard Python, one must also enter
676``root.update()`` to see the window. IDLE does the equivalent in the
677background, about 20 times a second, which is about every 50 milleseconds.
678Next enter ``b = tk.Button(root, text='button'); b.pack()``. Again,
679nothing visibly changes in standard Python until one enters ``root.update()``.
680
681Most tkinter programs run ``root.mainloop()``, which usually does not
682return until the tk app is destroyed. If the program is run with
683``python -i`` or from an IDLE editor, a ``>>>`` shell prompt does not
684appear until ``mainloop()`` returns, at which time there is nothing left
685to interact with.
686
687When running a tkinter program from an IDLE editor, one can comment out
688the mainloop call. One then gets a shell prompt immediately and can
689interact with the live application. One just has to remember to
690re-enable the mainloop call when running in standard Python.
691
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500692Running without a subprocess
693^^^^^^^^^^^^^^^^^^^^^^^^^^^^
694
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400695By default, IDLE executes user code in a separate subprocess via a socket,
Terry Jan Reedy6e10ec52015-09-23 20:00:33 -0400696which uses the internal loopback interface. This connection is not
697externally visible and no data is sent to or received from the Internet.
698If firewall software complains anyway, you can ignore it.
699
700If the attempt to make the socket connection fails, Idle will notify you.
701Such failures are sometimes transient, but if persistent, the problem
csabella9dc2b382017-04-29 18:28:36 -0400702may be either a firewall blocking the connection or misconfiguration of
Terry Jan Reedy6e10ec52015-09-23 20:00:33 -0400703a particular system. Until the problem is fixed, one can run Idle with
704the -n command line switch.
705
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500706If IDLE is started with the -n command line switch it will run in a
707single process and will not create the subprocess which runs the RPC
708Python execution server. This can be useful if Python cannot create
709the subprocess or the RPC socket interface on your platform. However,
710in this mode user code is not isolated from IDLE itself. Also, the
711environment is not restarted when Run/Run Module (F5) is selected. If
712your code has been modified, you must reload() the affected modules and
713re-import any specific items (e.g. from foo import baz) if the changes
714are to take effect. For these reasons, it is preferable to run IDLE
715with the default subprocess if at all possible.
716
717.. deprecated:: 3.4
718
Georg Brandl116aa622007-08-15 14:28:22 +0000719
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500720Help and preferences
721--------------------
722
Terry Jan Reedy18032632018-10-28 16:21:18 -0400723Help sources
724^^^^^^^^^^^^
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200725
Terry Jan Reedy18032632018-10-28 16:21:18 -0400726Help menu entry "IDLE Help" displays a formatted html version of the
727IDLE chapter of the Library Reference. The result, in a read-only
728tkinter text window, is close to what one sees in a web browser.
729Navigate through the text with a mousewheel,
730the scrollbar, or up and down arrow keys held down.
731Or click the TOC (Table of Contents) button and select a section
732header in the opened box.
733
734Help menu entry "Python Docs" opens the extensive sources of help,
735including tutorials, available at docs.python.org/x.y, where 'x.y'
736is the currently running Python version. If your system
737has an off-line copy of the docs (this may be an installation option),
738that will be opened instead.
739
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200740Selected URLs can be added or removed from the help menu at any time using the
Terry Jan Reedy18032632018-10-28 16:21:18 -0400741General tab of the Configure IDLE dialog .
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200742
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500743Setting preferences
744^^^^^^^^^^^^^^^^^^^
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200745
746The font preferences, highlighting, keys, and general preferences can be
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500747changed via Configure IDLE on the Option menu. Keys can be user defined;
csabella9dc2b382017-04-29 18:28:36 -0400748IDLE ships with four built-in key sets. In addition, a user can create a
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500749custom key set in the Configure IDLE dialog under the keys tab.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200750
751Extensions
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500752^^^^^^^^^^
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200753
csabella9dc2b382017-04-29 18:28:36 -0400754IDLE contains an extension facility. Preferences for extensions can be
Terry Jan Reedyadb4cd22017-09-12 07:45:15 -0400755changed with the Extensions tab of the preferences dialog. See the
756beginning of config-extensions.def in the idlelib directory for further
757information. The only current default extension is zzdummy, an example
758also used for testing.