blob: 75b6fa3861b23d09c50947816531485e38a7d0b4 [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 Reedyb65413b2018-11-15 13:15:13 -050023* cross-platform: works mostly the same on Windows, Unix, and macOS
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
Terry Jan Reedy50ff02b2018-11-10 23:26:31 -050043possible to have multiple editor windows simultaneously. On Windows and
44Linux, each has its own top menu. Each menu documented below indicates
45which window type it is associated with.
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050046
Terry Jan Reedy50ff02b2018-11-10 23:26:31 -050047Output windows, such as used for Edit => Find in Files, are a subtype of editor
48window. They currently have the same top menu but a different
49default title and context menu.
50
Terry Jan Reedyb65413b2018-11-15 13:15:13 -050051On macOS, there is one application menu. It dynamically changes according
Terry Jan Reedy50ff02b2018-11-10 23:26:31 -050052to the window currently selected. It has an IDLE menu, and some entries
Terry Jan Reedy8a533ff2019-05-16 01:20:37 -040053described below are moved around to conform to Apple guidelines.
Georg Brandl116aa622007-08-15 14:28:22 +000054
Andrew Svetlov1bd7f022013-01-14 19:27:36 +020055File menu (Shell and Editor)
56^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +000057
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050058New File
59 Create a new file editing window.
Georg Brandl116aa622007-08-15 14:28:22 +000060
61Open...
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050062 Open an existing file with an Open dialog.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +020063
64Recent Files
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050065 Open a list of recent files. Click one to open it.
66
67Open Module...
68 Open an existing module (searches sys.path).
Georg Brandl116aa622007-08-15 14:28:22 +000069
Terry Jan Reedyf5684942014-12-04 00:54:59 -050070.. index::
71 single: Class browser
72 single: Path browser
73
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050074Class Browser
75 Show functions, classes, and methods in the current Editor file in a
76 tree structure. In the shell, open a module first.
Georg Brandl116aa622007-08-15 14:28:22 +000077
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050078Path Browser
79 Show sys.path directories, modules, functions, classes and methods in a
80 tree structure.
Georg Brandl116aa622007-08-15 14:28:22 +000081
Georg Brandl116aa622007-08-15 14:28:22 +000082Save
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050083 Save the current window to the associated file, if there is one. Windows
84 that have been changed since being opened or last saved have a \* before
85 and after the window title. If there is no associated file,
86 do Save As instead.
Georg Brandl116aa622007-08-15 14:28:22 +000087
88Save As...
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050089 Save the current window with a Save As dialog. The file saved becomes the
90 new associated file for the window.
Georg Brandl116aa622007-08-15 14:28:22 +000091
92Save Copy As...
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050093 Save the current window to different file without changing the associated
94 file.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +020095
96Print Window
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -050097 Print the current window to the default printer.
Georg Brandl116aa622007-08-15 14:28:22 +000098
99Close
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500100 Close the current window (ask to save if unsaved).
Georg Brandl116aa622007-08-15 14:28:22 +0000101
102Exit
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500103 Close all windows and quit IDLE (ask to save unsaved windows).
Georg Brandl116aa622007-08-15 14:28:22 +0000104
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200105Edit menu (Shell and Editor)
106^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +0000107
108Undo
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500109 Undo the last change to the current window. A maximum of 1000 changes may
110 be undone.
Georg Brandl116aa622007-08-15 14:28:22 +0000111
112Redo
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500113 Redo the last undone change to the current window.
Georg Brandl116aa622007-08-15 14:28:22 +0000114
115Cut
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500116 Copy selection into the system-wide clipboard; then delete the selection.
Georg Brandl116aa622007-08-15 14:28:22 +0000117
118Copy
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500119 Copy selection into the system-wide clipboard.
Georg Brandl116aa622007-08-15 14:28:22 +0000120
121Paste
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500122 Insert contents of the system-wide clipboard into the current window.
123
124The clipboard functions are also available in context menus.
Georg Brandl116aa622007-08-15 14:28:22 +0000125
126Select All
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500127 Select the entire contents of the current window.
Georg Brandl116aa622007-08-15 14:28:22 +0000128
129Find...
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500130 Open a search dialog with many options
Georg Brandl116aa622007-08-15 14:28:22 +0000131
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500132Find Again
133 Repeat the last search, if there is one.
Georg Brandl116aa622007-08-15 14:28:22 +0000134
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500135Find Selection
136 Search for the currently selected string, if there is one.
Georg Brandl116aa622007-08-15 14:28:22 +0000137
138Find in Files...
Serhiy Storchaka6a7b3a72016-04-17 08:32:47 +0300139 Open a file search dialog. Put results in a new output window.
Georg Brandl116aa622007-08-15 14:28:22 +0000140
141Replace...
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500142 Open a search-and-replace dialog.
Georg Brandl116aa622007-08-15 14:28:22 +0000143
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500144Go to Line
Terry Jan Reedy2522db12020-03-08 14:32:42 -0400145 Move the cursor to the beginning of the line requested and make that
146 line visible. A request past the end of the file goes to the end.
147 Clear any selection and update the line and column status.
Georg Brandl116aa622007-08-15 14:28:22 +0000148
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500149Show Completions
Terry Jan Reedybce2eb42020-07-09 18:08:33 -0400150 Open a scrollable list allowing selection of existing names. See
Cheryl Sabella01421be2018-12-20 00:38:54 -0500151 :ref:`Completions <completions>` in the Editing and navigation section below.
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500152
153Expand Word
154 Expand a prefix you have typed to match a full word in the same window;
155 repeat to get a different expansion.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200156
157Show call tip
158 After an unclosed parenthesis for a function, open a small window with
Cheryl Sabella01421be2018-12-20 00:38:54 -0500159 function parameter hints. See :ref:`Calltips <calltips>` in the
160 Editing and navigation section below.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200161
162Show surrounding parens
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500163 Highlight the surrounding parenthesis.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200164
Terry Jan Reedy292cd6e2018-12-20 06:06:29 -0500165.. _format-menu:
166
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200167Format menu (Editor window only)
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500168^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200169
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500170Indent Region
171 Shift selected lines right by the indent width (default 4 spaces).
Georg Brandl116aa622007-08-15 14:28:22 +0000172
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500173Dedent Region
174 Shift selected lines left by the indent width (default 4 spaces).
Georg Brandl116aa622007-08-15 14:28:22 +0000175
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500176Comment Out Region
177 Insert ## in front of selected lines.
Georg Brandl116aa622007-08-15 14:28:22 +0000178
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500179Uncomment Region
180 Remove leading # or ## from selected lines.
Georg Brandl116aa622007-08-15 14:28:22 +0000181
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500182Tabify Region
183 Turn *leading* stretches of spaces into tabs. (Note: We recommend using
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200184 4 space blocks to indent Python code.)
Georg Brandl116aa622007-08-15 14:28:22 +0000185
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500186Untabify Region
187 Turn *all* tabs into the correct number of spaces.
Georg Brandl116aa622007-08-15 14:28:22 +0000188
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500189Toggle Tabs
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200190 Open a dialog to switch between indenting with spaces and tabs.
191
192New Indent Width
193 Open a dialog to change indent width. The accepted default by the Python
194 community is 4 spaces.
Georg Brandl116aa622007-08-15 14:28:22 +0000195
196Format Paragraph
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500197 Reformat the current blank-line-delimited paragraph in comment block or
198 multiline string or selected line in a string. All lines in the
199 paragraph will be formatted to less than N columns, where N defaults to 72.
Georg Brandl116aa622007-08-15 14:28:22 +0000200
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200201Strip trailing whitespace
Terry Jan Reedyff702892017-09-15 13:05:28 -0400202 Remove trailing space and other whitespace characters after the last
203 non-whitespace character of a line by applying str.rstrip to each line,
Terry Jan Reedy6bf644e2019-11-24 16:29:29 -0500204 including lines within multiline strings. Except for Shell windows,
205 remove extra newlines at the end of the file.
Georg Brandl116aa622007-08-15 14:28:22 +0000206
207.. index::
Georg Brandl116aa622007-08-15 14:28:22 +0000208 single: Run script
209
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200210Run menu (Editor window only)
211^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +0000212
Cheryl Sabella201bc2d2019-06-17 22:24:10 -0400213.. _run-module:
214
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500215Run Module
Cheryl Sabella201bc2d2019-06-17 22:24:10 -0400216 Do :ref:`Check Module <check-module>`. If no error, restart the shell to clean the
Terry Jan Reedy8b5a9812015-09-24 01:39:30 -0400217 environment, then execute the module. Output is displayed in the Shell
218 window. Note that output requires use of ``print`` or ``write``.
219 When execution is complete, the Shell retains focus and displays a prompt.
220 At this point, one may interactively explore the result of execution.
221 This is similar to executing a file with ``python -i file`` at a command
222 line.
Georg Brandl116aa622007-08-15 14:28:22 +0000223
Cheryl Sabella201bc2d2019-06-17 22:24:10 -0400224.. _run-custom:
225
226Run... Customized
227 Same as :ref:`Run Module <run-module>`, but run the module with customized
228 settings. *Command Line Arguments* extend :data:`sys.argv` as if passed
229 on a command line. The module can be run in the Shell without restarting.
230
Terry Jan Reedy14070292019-08-04 16:45:15 -0400231.. _check-module:
232
233Check Module
234 Check the syntax of the module currently open in the Editor window. If the
235 module has not been saved IDLE will either prompt the user to save or
236 autosave, as selected in the General tab of the Idle Settings dialog. If
237 there is a syntax error, the approximate location is indicated in the
238 Editor window.
239
240.. _python-shell:
241
242Python Shell
243 Open or wake up the Python Shell window.
244
Cheryl Sabella201bc2d2019-06-17 22:24:10 -0400245
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200246Shell menu (Shell window only)
247^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Ned Deily2778d0d2012-10-20 13:25:34 -0700248
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200249View Last Restart
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500250 Scroll the shell window to the last Shell restart.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200251
252Restart Shell
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500253 Restart the shell to clean the environment.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200254
Cheryl Sabellac0381aa2018-12-28 15:11:30 -0500255Previous History
256 Cycle through earlier commands in history which match the current entry.
257
258Next History
259 Cycle through later commands in history which match the current entry.
260
Terry Jan Reedy4b736762016-09-12 01:50:03 -0400261Interrupt Execution
262 Stop a running program.
263
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200264Debug menu (Shell window only)
265^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +0000266
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500267Go to File/Line
268 Look on the current line. with the cursor, and the line above for a filename
269 and line number. If found, open the file if not already open, and show the
270 line. Use this to view source lines referenced in an exception traceback
271 and lines found by Find in Files. Also available in the context menu of
272 the Shell window and Output windows.
Georg Brandl116aa622007-08-15 14:28:22 +0000273
274.. index::
Georg Brandl116aa622007-08-15 14:28:22 +0000275 single: debugger
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500276 single: stack viewer
277
278Debugger (toggle)
csabella9dc2b382017-04-29 18:28:36 -0400279 When activated, code entered in the Shell or run from an Editor will run
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500280 under the debugger. In the Editor, breakpoints can be set with the context
281 menu. This feature is still incomplete and somewhat experimental.
282
283Stack Viewer
284 Show the stack traceback of the last exception in a tree widget, with
285 access to locals and globals.
286
287Auto-open Stack Viewer
288 Toggle automatically opening the stack viewer on an unhandled exception.
Georg Brandl116aa622007-08-15 14:28:22 +0000289
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200290Options menu (Shell and Editor)
291^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +0000292
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200293Configure IDLE
Terry Jan Reedy93f35422015-10-13 22:03:51 -0400294 Open a configuration dialog and change preferences for the following:
295 fonts, indentation, keybindings, text color themes, startup windows and
Tal Einat7123ea02019-07-23 15:22:11 +0300296 size, additional help sources, and extensions. On macOS, open the
Terry Jan Reedy292cd6e2018-12-20 06:06:29 -0500297 configuration dialog by selecting Preferences in the application
Tal Einat7123ea02019-07-23 15:22:11 +0300298 menu. For more details, see
Terry Jan Reedy292cd6e2018-12-20 06:06:29 -0500299 :ref:`Setting preferences <preferences>` under Help and preferences.
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500300
Terry Jan Reedy14070292019-08-04 16:45:15 -0400301Most configuration options apply to all windows or all future windows.
302The option items below only apply to the active window.
Tal Einat7123ea02019-07-23 15:22:11 +0300303
Cheryl Sabellac1b4b0f2018-12-22 01:25:45 -0500304Show/Hide Code Context (Editor Window only)
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200305 Open a pane at the top of the edit window which shows the block context
Cheryl Sabella01421be2018-12-20 00:38:54 -0500306 of the code which has scrolled above the top of the window. See
Tal Einat7123ea02019-07-23 15:22:11 +0300307 :ref:`Code Context <code-context>` in the Editing and Navigation section
308 below.
309
310Show/Hide Line Numbers (Editor Window only)
311 Open a column to the left of the edit window which shows the number
312 of each line of text. The default is off, which may be changed in the
313 preferences (see :ref:`Setting preferences <preferences>`).
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200314
Terry Jan Reedydf9b0322019-05-27 19:16:46 -0400315Zoom/Restore Height
316 Toggles the window between normal size and maximum height. The initial size
317 defaults to 40 lines by 80 chars unless changed on the General tab of the
Tal Einat5bff3c82019-06-17 22:41:00 +0300318 Configure IDLE dialog. The maximum height for a screen is determined by
319 momentarily maximizing a window the first time one is zoomed on the screen.
Tal Einat7123ea02019-07-23 15:22:11 +0300320 Changing screen settings may invalidate the saved height. This toggle has
Tal Einat5bff3c82019-06-17 22:41:00 +0300321 no effect when a window is maximized.
Terry Jan Reedydf9b0322019-05-27 19:16:46 -0400322
Ned Deilyccb416f2015-01-17 21:06:27 -0800323Window menu (Shell and Editor)
324^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200325
Cheryl Sabellac1b4b0f2018-12-22 01:25:45 -0500326Lists the names of all open windows; select one to bring it to the foreground
327(deiconifying it if necessary).
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200328
329Help menu (Shell and Editor)
330^^^^^^^^^^^^^^^^^^^^^^^^^^^^
331
332About IDLE
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500333 Display version, copyright, license, credits, and more.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200334
335IDLE Help
Terry Jan Reedy18032632018-10-28 16:21:18 -0400336 Display this IDLE document, detailing the menu options, basic editing and
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200337 navigation, and other tips.
338
339Python Docs
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500340 Access local Python documentation, if installed, or start a web browser
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200341 and open docs.python.org showing the latest Python documentation.
342
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500343Turtle Demo
Andrés Delfino271818f2018-09-14 14:13:09 -0300344 Run the turtledemo module with example Python code and turtle drawings.
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500345
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200346Additional help sources may be added here with the Configure IDLE dialog under
Cheryl Sabella01421be2018-12-20 00:38:54 -0500347the General tab. See the :ref:`Help sources <help-sources>` subsection below
348for more on Help menu choices.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200349
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500350.. index::
351 single: Cut
352 single: Copy
353 single: Paste
354 single: Set Breakpoint
355 single: Clear Breakpoint
356 single: breakpoints
357
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500358Context Menus
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200359^^^^^^^^^^^^^^^^^^^^^^^^^^
360
Terry Jan Reedyb65413b2018-11-15 13:15:13 -0500361Open a context menu by right-clicking in a window (Control-click on macOS).
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500362Context menus have the standard clipboard functions also on the Edit menu.
Ned Deily2778d0d2012-10-20 13:25:34 -0700363
Andrew Svetlovd1837672012-11-01 22:41:19 +0200364Cut
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500365 Copy selection into the system-wide clipboard; then delete the selection.
Andrew Svetlovd1837672012-11-01 22:41:19 +0200366
367Copy
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500368 Copy selection into the system-wide clipboard.
Andrew Svetlovd1837672012-11-01 22:41:19 +0200369
370Paste
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500371 Insert contents of the system-wide clipboard into the current window.
372
373Editor windows also have breakpoint functions. Lines with a breakpoint set are
374specially marked. Breakpoints only have an effect when running under the
Tal Einatd6c08db2020-01-06 01:51:48 +0200375debugger. Breakpoints for a file are saved in the user's ``.idlerc``
376directory.
Andrew Svetlovd1837672012-11-01 22:41:19 +0200377
Ned Deily2778d0d2012-10-20 13:25:34 -0700378Set Breakpoint
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500379 Set a breakpoint on the current line.
Ned Deily2778d0d2012-10-20 13:25:34 -0700380
381Clear Breakpoint
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500382 Clear the breakpoint on that line.
Ned Deily2778d0d2012-10-20 13:25:34 -0700383
Terry Jan Reedy68d6dc02018-10-28 12:44:44 -0400384Shell and Output windows also have the following.
Andrew Svetlovd1837672012-11-01 22:41:19 +0200385
Ned Deily2778d0d2012-10-20 13:25:34 -0700386Go to file/line
387 Same as in Debug menu.
388
Benjamin Peterson577277f2019-03-25 21:46:35 -0700389The Shell window also has an output squeezing facility explained in the *Python
390Shell window* subsection below.
Terry Jan Reedy68d6dc02018-10-28 12:44:44 -0400391
392Squeeze
393 If the cursor is over an output line, squeeze all the output between
394 the code above and the prompt below down to a 'Squeezed text' label.
395
Ned Deily2778d0d2012-10-20 13:25:34 -0700396
Cheryl Sabella01421be2018-12-20 00:38:54 -0500397.. _editing-and-navigation:
398
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200399Editing and navigation
400----------------------
Georg Brandl116aa622007-08-15 14:28:22 +0000401
Terry Jan Reedyea9c8bd2018-10-28 20:42:18 -0400402Editor windows
403^^^^^^^^^^^^^^
404
405IDLE may open editor windows when it starts, depending on settings
406and how you start IDLE. Thereafter, use the File menu. There can be only
407one open editor window for a given file.
408
409The title bar contains the name of the file, the full path, and the version
410of Python and IDLE running the window. The status bar contains the line
411number ('Ln') and column number ('Col'). Line numbers start with 1;
412column numbers with 0.
413
414IDLE assumes that files with a known .py* extension contain Python code
415and that other files do not. Run Python code with the Run menu.
416
417Key bindings
418^^^^^^^^^^^^
419
Serhiy Storchaka0424eaf2015-09-12 17:45:25 +0300420In this section, 'C' refers to the :kbd:`Control` key on Windows and Unix and
Terry Jan Reedyb65413b2018-11-15 13:15:13 -0500421the :kbd:`Command` key on macOS.
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500422
Georg Brandl116aa622007-08-15 14:28:22 +0000423* :kbd:`Backspace` deletes to the left; :kbd:`Del` deletes to the right
424
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200425* :kbd:`C-Backspace` delete word left; :kbd:`C-Del` delete word to the right
426
Georg Brandl116aa622007-08-15 14:28:22 +0000427* Arrow keys and :kbd:`Page Up`/:kbd:`Page Down` to move around
428
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200429* :kbd:`C-LeftArrow` and :kbd:`C-RightArrow` moves by words
430
Georg Brandl116aa622007-08-15 14:28:22 +0000431* :kbd:`Home`/:kbd:`End` go to begin/end of line
432
433* :kbd:`C-Home`/:kbd:`C-End` go to begin/end of file
434
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200435* Some useful Emacs bindings are inherited from Tcl/Tk:
436
437 * :kbd:`C-a` beginning of line
438
439 * :kbd:`C-e` end of line
440
441 * :kbd:`C-k` kill line (but doesn't put it in clipboard)
442
443 * :kbd:`C-l` center window around the insertion point
444
csabella9dc2b382017-04-29 18:28:36 -0400445 * :kbd:`C-b` go backward one character without deleting (usually you can
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200446 also use the cursor key for this)
447
448 * :kbd:`C-f` go forward one character without deleting (usually you can
449 also use the cursor key for this)
450
451 * :kbd:`C-p` go up one line (usually you can also use the cursor key for
452 this)
453
454 * :kbd:`C-d` delete next character
455
456Standard keybindings (like :kbd:`C-c` to copy and :kbd:`C-v` to paste)
457may work. Keybindings are selected in the Configure IDLE dialog.
Georg Brandl116aa622007-08-15 14:28:22 +0000458
Georg Brandl116aa622007-08-15 14:28:22 +0000459Automatic indentation
460^^^^^^^^^^^^^^^^^^^^^
461
462After a block-opening statement, the next line is indented by 4 spaces (in the
463Python Shell window by one tab). After certain keywords (break, return etc.)
464the next line is dedented. In leading indentation, :kbd:`Backspace` deletes up
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200465to 4 spaces if they are there. :kbd:`Tab` inserts spaces (in the Python
csabella9dc2b382017-04-29 18:28:36 -0400466Shell window one tab), number depends on Indent width. Currently, tabs
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200467are restricted to four spaces due to Tcl/Tk limitations.
Georg Brandl116aa622007-08-15 14:28:22 +0000468
Terry Jan Reedy292cd6e2018-12-20 06:06:29 -0500469See also the indent/dedent region commands on the
470:ref:`Format menu <format-menu>`.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200471
Cheryl Sabella01421be2018-12-20 00:38:54 -0500472.. _completions:
473
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200474Completions
475^^^^^^^^^^^
476
Terry Jan Reedybce2eb42020-07-09 18:08:33 -0400477Completions are supplied, when requested and available, for module
478names, attributes of classes or functions, or filenames. Each request
479method displays a completion box with existing names. (See tab
480completions below for an exception.) For any box, change the name
481being completed and the item highlighted in the box by
482typing and deleting characters; by hitting :kbd:`Up`, :kbd:`Down`,
483:kbd:`PageUp`, :kbd:`PageDown`, :kbd:`Home`, and :kbd:`End` keys;
484and by a single click within the box. Close the box with :kbd:`Escape`,
485:kbd:`Enter`, and double :kbd:`Tab` keys or clicks outside the box.
486A double click within the box selects and closes.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200487
Terry Jan Reedybce2eb42020-07-09 18:08:33 -0400488One way to open a box is to type a key character and wait for a
489predefined interval. This defaults to 2 seconds; customize it
490in the settings dialog. (To prevent auto popups, set the delay to a
491large number of milliseconds, such as 100000000.) For imported module
492names or class or function attributes, type '.'.
493For filenames in the root directory, type :data:`os.sep` or
494data:`os.altsep` immediately after an opening quote. (On Windows,
495one can specify a drive first.) Move into subdirectories by typing a
496directory name and a separator.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200497
Terry Jan Reedybce2eb42020-07-09 18:08:33 -0400498Instead of waiting, or after a box is closed, open a completion box
499immediately with Show Completions on the Edit menu. The default hot
500key is :kbd:`C-space`. If one types a prefix for the desired name
501before opening the box, the first match or near miss is made visible.
502The result is the same as if one enters a prefix
503after the box is displayed. Show Completions after a quote completes
504filenames in the current directory instead of a root directory.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200505
Terry Jan Reedybce2eb42020-07-09 18:08:33 -0400506Hitting :kbd:`Tab` after a prefix usually has the same effect as Show
507Completions. (With no prefix, it indents.) However, if there is only
508one match to the prefix, that match is immediately added to the editor
509text without opening a box.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200510
Terry Jan Reedybce2eb42020-07-09 18:08:33 -0400511Invoking 'Show Completions', or hitting :kbd:`Tab` after a prefix,
512outside of a string and without a preceding '.' opens a box with
513keywords, builtin names, and available module-level names.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200514
Terry Jan Reedybce2eb42020-07-09 18:08:33 -0400515When editing code in an editor (as oppose to Shell), increase the
516available module-level names by running your code
517and not restarting the Shell thereafter. This is especially useful
518after adding imports at the top of a file. This also increases
519possible attribute completions.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200520
Terry Jan Reedybce2eb42020-07-09 18:08:33 -0400521Completion boxes intially exclude names beginning with '_' or, for
522modules, not included in '__all__'. The hidden names can be accessed
523by typing '_' after '.', either before or after the box is opened.
Terry Jan Reedy37f81352015-09-29 01:55:57 -0400524
Cheryl Sabella01421be2018-12-20 00:38:54 -0500525.. _calltips:
526
Terry Jan Reedy37f81352015-09-29 01:55:57 -0400527Calltips
528^^^^^^^^
529
Alex Gaynor1cf2a802017-02-28 22:26:56 -0500530A calltip is shown when one types :kbd:`(` after the name of an *accessible*
Terry Jan Reedy37f81352015-09-29 01:55:57 -0400531function. A name expression may include dots and subscripts. A calltip
532remains until it is clicked, the cursor is moved out of the argument area,
533or :kbd:`)` is typed. When the cursor is in the argument part of a definition,
534the menu or shortcut display a calltip.
535
536A calltip consists of the function signature and the first line of the
537docstring. For builtins without an accessible signature, the calltip
538consists of all lines up the fifth line or the first blank line. These
539details may change.
540
541The set of *accessible* functions depends on what modules have been imported
542into the user process, including those imported by Idle itself,
543and what definitions have been run, all since the last restart.
544
545For example, restart the Shell and enter ``itertools.count(``. A calltip
546appears because Idle imports itertools into the user process for its own use.
547(This could change.) Enter ``turtle.write(`` and nothing appears. Idle does
548not import turtle. The menu or shortcut do nothing either. Enter
549``import turtle`` and then ``turtle.write(`` will work.
550
551In an editor, import statements have no effect until one runs the file. One
552might want to run a file after writing the import statements at the top,
553or immediately run an existing file before editing.
Georg Brandl116aa622007-08-15 14:28:22 +0000554
Cheryl Sabella01421be2018-12-20 00:38:54 -0500555.. _code-context:
556
557Code Context
558^^^^^^^^^^^^
559
560Within an editor window containing Python code, code context can be toggled
561in order to show or hide a pane at the top of the window. When shown, this
562pane freezes the opening lines for block code, such as those beginning with
563``class``, ``def``, or ``if`` keywords, that would have otherwise scrolled
564out of view. The size of the pane will be expanded and contracted as needed
565to show the all current levels of context, up to the maximum number of
566lines defined in the Configure IDLE dialog (which defaults to 15). If there
567are no current context lines and the feature is toggled on, a single blank
568line will display. Clicking on a line in the context pane will move that
569line to the top of the editor.
570
571The text and background colors for the context pane can be configured under
572the Highlights tab in the Configure IDLE dialog.
573
Georg Brandl116aa622007-08-15 14:28:22 +0000574Python Shell window
575^^^^^^^^^^^^^^^^^^^
576
Terry Jan Reedy75d9d592018-11-06 12:37:36 -0500577With IDLE's Shell, one enters, edits, and recalls complete statements.
578Most consoles and terminals only work with a single physical line at a time.
579
580When one pastes code into Shell, it is not compiled and possibly executed
581until one hits :kbd:`Return`. One may edit pasted code first.
582If one pastes more that one statement into Shell, the result will be a
583:exc:`SyntaxError` when multiple statements are compiled as if they were one.
584
585The editing features described in previous subsections work when entering
586code interactively. IDLE's Shell window also responds to the following keys.
Terry Jan Reedy68d6dc02018-10-28 12:44:44 -0400587
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200588* :kbd:`C-c` interrupts executing command
Georg Brandl116aa622007-08-15 14:28:22 +0000589
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200590* :kbd:`C-d` sends end-of-file; closes window if typed at a ``>>>`` prompt
Georg Brandl116aa622007-08-15 14:28:22 +0000591
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200592* :kbd:`Alt-/` (Expand word) is also useful to reduce typing
Georg Brandl116aa622007-08-15 14:28:22 +0000593
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200594 Command history
Georg Brandl116aa622007-08-15 14:28:22 +0000595
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200596 * :kbd:`Alt-p` retrieves previous command matching what you have typed. On
Terry Jan Reedyb65413b2018-11-15 13:15:13 -0500597 macOS use :kbd:`C-p`.
Georg Brandl116aa622007-08-15 14:28:22 +0000598
Terry Jan Reedyb65413b2018-11-15 13:15:13 -0500599 * :kbd:`Alt-n` retrieves next. On macOS use :kbd:`C-n`.
Georg Brandl116aa622007-08-15 14:28:22 +0000600
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200601 * :kbd:`Return` while on any previous command retrieves that command
Georg Brandl116aa622007-08-15 14:28:22 +0000602
Terry Jan Reedyf660ce22015-09-24 23:13:49 -0400603Text colors
604^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +0000605
Terry Jan Reedyf660ce22015-09-24 23:13:49 -0400606Idle defaults to black on white text, but colors text with special meanings.
607For the shell, these are shell output, shell error, user output, and
608user error. For Python code, at the shell prompt or in an editor, these are
609keywords, builtin class and function names, names following ``class`` and
610``def``, strings, and comments. For any text window, these are the cursor (when
611present), found text (when possible), and selected text.
Georg Brandl116aa622007-08-15 14:28:22 +0000612
Terry Jan Reedyf660ce22015-09-24 23:13:49 -0400613Text coloring is done in the background, so uncolorized text is occasionally
614visible. To change the color scheme, use the Configure IDLE dialog
615Highlighting tab. The marking of debugger breakpoint lines in the editor and
616text in popups and dialogs is not user-configurable.
Georg Brandl116aa622007-08-15 14:28:22 +0000617
618
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400619Startup and code execution
620--------------------------
Benjamin Petersonf07d0022009-03-21 17:31:58 +0000621
622Upon startup with the ``-s`` option, IDLE will execute the file referenced by
623the environment variables :envvar:`IDLESTARTUP` or :envvar:`PYTHONSTARTUP`.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200624IDLE first checks for ``IDLESTARTUP``; if ``IDLESTARTUP`` is present the file
625referenced is run. If ``IDLESTARTUP`` is not present, IDLE checks for
Benjamin Petersonf07d0022009-03-21 17:31:58 +0000626``PYTHONSTARTUP``. Files referenced by these environment variables are
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200627convenient places to store functions that are used frequently from the IDLE
Benjamin Petersonf07d0022009-03-21 17:31:58 +0000628shell, or for executing import statements to import common modules.
629
630In addition, ``Tk`` also loads a startup file if it is present. Note that the
631Tk file is loaded unconditionally. This additional file is ``.Idle.py`` and is
632looked for in the user's home directory. Statements in this file will be
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500633executed in the Tk namespace, so this file is not useful for importing
634functions to be used from IDLE's Python shell.
Benjamin Petersonf07d0022009-03-21 17:31:58 +0000635
Georg Brandl116aa622007-08-15 14:28:22 +0000636Command line usage
637^^^^^^^^^^^^^^^^^^
638
Martin Panter1050d2d2016-07-26 11:18:21 +0200639.. code-block:: none
Georg Brandl116aa622007-08-15 14:28:22 +0000640
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400641 idle.py [-c command] [-d] [-e] [-h] [-i] [-r file] [-s] [-t title] [-] [arg] ...
Georg Brandl116aa622007-08-15 14:28:22 +0000642
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400643 -c command run command in the shell window
644 -d enable debugger and open shell window
645 -e open editor window
Terry Jan Reedy3399e1e2016-08-30 16:58:01 -0400646 -h print help message with legal combinations and exit
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400647 -i open shell window
648 -r file run file in shell window
649 -s run $IDLESTARTUP or $PYTHONSTARTUP first, in shell window
Georg Brandl116aa622007-08-15 14:28:22 +0000650 -t title set title of shell window
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400651 - run stdin in shell (- must be last option before args)
Georg Brandl116aa622007-08-15 14:28:22 +0000652
653If there are arguments:
654
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400655* If ``-``, ``-c``, or ``r`` is used, all arguments are placed in
656 ``sys.argv[1:...]`` and ``sys.argv[0]`` is set to ``''``, ``'-c'``,
657 or ``'-r'``. No editor window is opened, even if that is the default
658 set in the Options dialog.
Georg Brandl116aa622007-08-15 14:28:22 +0000659
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400660* Otherwise, arguments are files opened for editing and
661 ``sys.argv`` reflects the arguments passed to IDLE itself.
Georg Brandl116aa622007-08-15 14:28:22 +0000662
terryjreedy188aedf2017-06-13 21:32:16 -0400663Startup failure
664^^^^^^^^^^^^^^^
665
666IDLE uses a socket to communicate between the IDLE GUI process and the user
667code execution process. A connection must be established whenever the Shell
668starts or restarts. (The latter is indicated by a divider line that says
669'RESTART'). If the user process fails to connect to the GUI process, it
670displays a ``Tk`` error box with a 'cannot connect' message that directs the
671user here. It then exits.
672
673A common cause of failure is a user-written file with the same name as a
674standard library module, such as *random.py* and *tkinter.py*. When such a
675file is located in the same directory as a file that is about to be run,
676IDLE cannot import the stdlib file. The current fix is to rename the
677user file.
678
679Though less common than in the past, an antivirus or firewall program may
680stop the connection. If the program cannot be taught to allow the
681connection, then it must be turned off for IDLE to work. It is safe to
682allow this internal connection because no data is visible on external
683ports. A similar problem is a network mis-configuration that blocks
684connections.
685
686Python installation issues occasionally stop IDLE: multiple versions can
687clash, or a single installation might need admin access. If one undo the
688clash, or cannot or does not want to run as admin, it might be easiest to
689completely remove Python and start over.
690
691A zombie pythonw.exe process could be a problem. On Windows, use Task
Jules Lasne (jlasne)ce305d62020-03-06 02:28:14 +0100692Manager to check for one and stop it if there is. Sometimes a restart
693initiated by a program crash or Keyboard Interrupt (control-C) may fail
694to connect. Dismissing the error box or using Restart Shell on the Shell
695menu may fix a temporary problem.
terryjreedy188aedf2017-06-13 21:32:16 -0400696
697When IDLE first starts, it attempts to read user configuration files in
Tal Einatd6c08db2020-01-06 01:51:48 +0200698``~/.idlerc/`` (~ is one's home directory). If there is a problem, an error
terryjreedy188aedf2017-06-13 21:32:16 -0400699message should be displayed. Leaving aside random disk glitches, this can
Jules Lasne (jlasne)ce305d62020-03-06 02:28:14 +0100700be prevented by never editing the files by hand. Instead, use the
701configuration dialog, under Options. Once there is an error in a user
702configuration file, the best solution may be to delete it and start over
703with the settings dialog.
terryjreedy188aedf2017-06-13 21:32:16 -0400704
705If IDLE quits with no message, and it was not started from a console, try
Jules Lasne (jlasne)ce305d62020-03-06 02:28:14 +0100706starting it from a console or terminal (``python -m idlelib``) and see if
707this results in an error message.
terryjreedy188aedf2017-06-13 21:32:16 -0400708
Terry Jan Reedy5e790902018-11-05 21:30:32 -0500709Running user code
710^^^^^^^^^^^^^^^^^
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400711
Terry Jan Reedy98758bc2017-09-12 09:05:16 -0400712With rare exceptions, the result of executing Python code with IDLE is
Terry Jan Reedy5e790902018-11-05 21:30:32 -0500713intended to be the same as executing the same code by the default method,
714directly with Python in a text-mode system console or terminal window.
Terry Jan Reedy98758bc2017-09-12 09:05:16 -0400715However, the different interface and operation occasionally affect
Terry Jan Reedy5e790902018-11-05 21:30:32 -0500716visible results. For instance, ``sys.modules`` starts with more entries,
717and ``threading.activeCount()`` returns 2 instead of 1.
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400718
Terry Jan Reedy5e790902018-11-05 21:30:32 -0500719By default, IDLE runs user code in a separate OS process rather than in
720the user interface process that runs the shell and editor. In the execution
721process, it replaces ``sys.stdin``, ``sys.stdout``, and ``sys.stderr``
722with objects that get input from and send output to the Shell window.
723The original values stored in ``sys.__stdin__``, ``sys.__stdout__``, and
724``sys.__stderr__`` are not touched, but may be ``None``.
725
Terry Jan Reedy98758bc2017-09-12 09:05:16 -0400726When Shell has the focus, it controls the keyboard and screen. This is
727normally transparent, but functions that directly access the keyboard
Terry Jan Reedy5e790902018-11-05 21:30:32 -0500728and screen will not work. These include system-specific functions that
729determine whether a key has been pressed and if so, which.
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400730
Terry Jan Reedy5e790902018-11-05 21:30:32 -0500731IDLE's standard stream replacements are not inherited by subprocesses
732created in the execution process, whether directly by user code or by modules
733such as multiprocessing. If such subprocess use ``input`` from sys.stdin
734or ``print`` or ``write`` to sys.stdout or sys.stderr,
735IDLE should be started in a command line window. The secondary subprocess
736will then be attached to that window for input and output.
737
Tal Einatfcf1d002019-07-06 15:35:24 +0300738The IDLE code running in the execution process adds frames to the call stack
739that would not be there otherwise. IDLE wraps ``sys.getrecursionlimit`` and
740``sys.setrecursionlimit`` to reduce the effect of the additional stack frames.
741
Terry Jan Reedy5e790902018-11-05 21:30:32 -0500742If ``sys`` is reset by user code, such as with ``importlib.reload(sys)``,
743IDLE's changes are lost and input from the keyboard and output to the screen
744will not work correctly.
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400745
Terry Jan Reedy6d965b32019-05-19 22:52:22 -0400746When user code raises SystemExit either directly or by calling sys.exit, IDLE
747returns to a Shell prompt instead of exiting.
748
Terry Jan Reedy75d9d592018-11-06 12:37:36 -0500749User output in Shell
750^^^^^^^^^^^^^^^^^^^^
751
752When a program outputs text, the result is determined by the
753corresponding output device. When IDLE executes user code, ``sys.stdout``
754and ``sys.stderr`` are connected to the display area of IDLE's Shell. Some of
755its features are inherited from the underlying Tk Text widget. Others
Terry Jan Reedy76cd0c32018-11-06 23:55:06 -0500756are programmed additions. Where it matters, Shell is designed for development
757rather than production runs.
758
759For instance, Shell never throws away output. A program that sends unlimited
760output to Shell will eventually fill memory, resulting in a memory error.
761In contrast, some system text windows only keep the last n lines of output.
762A Windows console, for instance, keeps a user-settable 1 to 9999 lines,
763with 300 the default.
Terry Jan Reedy75d9d592018-11-06 12:37:36 -0500764
Benjamin Peterson577277f2019-03-25 21:46:35 -0700765A Tk Text widget, and hence IDLE's Shell, displays characters (codepoints) in
766the BMP (Basic Multilingual Plane) subset of Unicode. Which characters are
767displayed with a proper glyph and which with a replacement box depends on the
768operating system and installed fonts. Tab characters cause the following text
769to begin after the next tab stop. (They occur every 8 'characters'). Newline
770characters cause following text to appear on a new line. Other control
771characters are ignored or displayed as a space, box, or something else,
772depending on the operating system and font. (Moving the text cursor through
Terry Jan Reedy55d03512019-04-26 23:22:36 -0400773such output with arrow keys may exhibit some surprising spacing behavior.) ::
Terry Jan Reedy8a03ff22019-02-08 22:51:51 -0500774
Terry Jan Reedy55d03512019-04-26 23:22:36 -0400775 >>> s = 'a\tb\a<\x02><\r>\bc\nd' # Enter 22 chars.
Terry Jan Reedy8a03ff22019-02-08 22:51:51 -0500776 >>> len(s)
777 14
778 >>> s # Display repr(s)
779 'a\tb\x07<\x02><\r>\x08c\nd'
780 >>> print(s, end='') # Display s as is.
781 # Result varies by OS and font. Try it.
782
783The ``repr`` function is used for interactive echo of expression
784values. It returns an altered version of the input string in which
785control codes, some BMP codepoints, and all non-BMP codepoints are
786replaced with escape codes. As demonstrated above, it allows one to
787identify the characters in a string, regardless of how they are displayed.
Terry Jan Reedy75d9d592018-11-06 12:37:36 -0500788
789Normal and error output are generally kept separate (on separate lines)
790from code input and each other. They each get different highlight colors.
791
792For SyntaxError tracebacks, the normal '^' marking where the error was
793detected is replaced by coloring the text with an error highlight.
794When code run from a file causes other exceptions, one may right click
795on a traceback line to jump to the corresponding line in an IDLE editor.
796The file will be opened if necessary.
797
798Shell has a special facility for squeezing output lines down to a
799'Squeezed text' label. This is done automatically
800for output over N lines (N = 50 by default).
801N can be changed in the PyShell section of the General
802page of the Settings dialog. Output with fewer lines can be squeezed by
803right clicking on the output. This can be useful lines long enough to slow
804down scrolling.
805
806Squeezed output is expanded in place by double-clicking the label.
807It can also be sent to the clipboard or a separate view window by
808right-clicking the label.
809
Terry Jan Reedy98758bc2017-09-12 09:05:16 -0400810Developing tkinter applications
811^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
812
813IDLE is intentionally different from standard Python in order to
814facilitate development of tkinter programs. Enter ``import tkinter as tk;
815root = tk.Tk()`` in standard Python and nothing appears. Enter the same
816in IDLE and a tk window appears. In standard Python, one must also enter
817``root.update()`` to see the window. IDLE does the equivalent in the
Terry Jan Reedy8a533ff2019-05-16 01:20:37 -0400818background, about 20 times a second, which is about every 50 milliseconds.
Terry Jan Reedy98758bc2017-09-12 09:05:16 -0400819Next enter ``b = tk.Button(root, text='button'); b.pack()``. Again,
820nothing visibly changes in standard Python until one enters ``root.update()``.
821
822Most tkinter programs run ``root.mainloop()``, which usually does not
823return until the tk app is destroyed. If the program is run with
824``python -i`` or from an IDLE editor, a ``>>>`` shell prompt does not
825appear until ``mainloop()`` returns, at which time there is nothing left
826to interact with.
827
828When running a tkinter program from an IDLE editor, one can comment out
829the mainloop call. One then gets a shell prompt immediately and can
830interact with the live application. One just has to remember to
831re-enable the mainloop call when running in standard Python.
832
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500833Running without a subprocess
834^^^^^^^^^^^^^^^^^^^^^^^^^^^^
835
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400836By default, IDLE executes user code in a separate subprocess via a socket,
Terry Jan Reedy6e10ec52015-09-23 20:00:33 -0400837which uses the internal loopback interface. This connection is not
838externally visible and no data is sent to or received from the Internet.
839If firewall software complains anyway, you can ignore it.
840
841If the attempt to make the socket connection fails, Idle will notify you.
842Such failures are sometimes transient, but if persistent, the problem
csabella9dc2b382017-04-29 18:28:36 -0400843may be either a firewall blocking the connection or misconfiguration of
Terry Jan Reedy6e10ec52015-09-23 20:00:33 -0400844a particular system. Until the problem is fixed, one can run Idle with
845the -n command line switch.
846
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500847If IDLE is started with the -n command line switch it will run in a
848single process and will not create the subprocess which runs the RPC
849Python execution server. This can be useful if Python cannot create
850the subprocess or the RPC socket interface on your platform. However,
851in this mode user code is not isolated from IDLE itself. Also, the
852environment is not restarted when Run/Run Module (F5) is selected. If
853your code has been modified, you must reload() the affected modules and
854re-import any specific items (e.g. from foo import baz) if the changes
855are to take effect. For these reasons, it is preferable to run IDLE
856with the default subprocess if at all possible.
857
858.. deprecated:: 3.4
859
Georg Brandl116aa622007-08-15 14:28:22 +0000860
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500861Help and preferences
862--------------------
863
Cheryl Sabella01421be2018-12-20 00:38:54 -0500864.. _help-sources:
865
Terry Jan Reedy18032632018-10-28 16:21:18 -0400866Help sources
867^^^^^^^^^^^^
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200868
Terry Jan Reedy18032632018-10-28 16:21:18 -0400869Help menu entry "IDLE Help" displays a formatted html version of the
870IDLE chapter of the Library Reference. The result, in a read-only
871tkinter text window, is close to what one sees in a web browser.
872Navigate through the text with a mousewheel,
873the scrollbar, or up and down arrow keys held down.
874Or click the TOC (Table of Contents) button and select a section
875header in the opened box.
876
877Help menu entry "Python Docs" opens the extensive sources of help,
Tal Einatd6c08db2020-01-06 01:51:48 +0200878including tutorials, available at ``docs.python.org/x.y``, where 'x.y'
Terry Jan Reedy18032632018-10-28 16:21:18 -0400879is the currently running Python version. If your system
880has an off-line copy of the docs (this may be an installation option),
881that will be opened instead.
882
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200883Selected URLs can be added or removed from the help menu at any time using the
Tal Einatd6c08db2020-01-06 01:51:48 +0200884General tab of the Configure IDLE dialog.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200885
Terry Jan Reedy292cd6e2018-12-20 06:06:29 -0500886.. _preferences:
887
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500888Setting preferences
889^^^^^^^^^^^^^^^^^^^
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200890
891The font preferences, highlighting, keys, and general preferences can be
Terry Jan Reedy292cd6e2018-12-20 06:06:29 -0500892changed via Configure IDLE on the Option menu.
Tal Einatd6c08db2020-01-06 01:51:48 +0200893Non-default user settings are saved in a ``.idlerc`` directory in the user's
Terry Jan Reedy292cd6e2018-12-20 06:06:29 -0500894home directory. Problems caused by bad user configuration files are solved
Tal Einatd6c08db2020-01-06 01:51:48 +0200895by editing or deleting one or more of the files in ``.idlerc``.
Terry Jan Reedy292cd6e2018-12-20 06:06:29 -0500896
Terry Jan Reedyd6101162019-02-23 23:04:53 -0500897On the Font tab, see the text sample for the effect of font face and size
898on multiple characters in multiple languages. Edit the sample to add
899other characters of personal interest. Use the sample to select
900monospaced fonts. If particular characters have problems in Shell or an
901editor, add them to the top of the sample and try changing first size
902and then font.
903
Terry Jan Reedy292cd6e2018-12-20 06:06:29 -0500904On the Highlights and Keys tab, select a built-in or custom color theme
905and key set. To use a newer built-in color theme or key set with older
906IDLEs, save it as a new custom theme or key set and it well be accessible
907to older IDLEs.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200908
Terry Jan Reedyb65413b2018-11-15 13:15:13 -0500909IDLE on macOS
Terry Jan Reedy50ff02b2018-11-10 23:26:31 -0500910^^^^^^^^^^^^^
911
912Under System Preferences: Dock, one can set "Prefer tabs when opening
913documents" to "Always". This setting is not compatible with the tk/tkinter
914GUI framework used by IDLE, and it breaks a few IDLE features.
915
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200916Extensions
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500917^^^^^^^^^^
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200918
csabella9dc2b382017-04-29 18:28:36 -0400919IDLE contains an extension facility. Preferences for extensions can be
Terry Jan Reedyadb4cd22017-09-12 07:45:15 -0400920changed with the Extensions tab of the preferences dialog. See the
921beginning of config-extensions.def in the idlelib directory for further
922information. The only current default extension is zzdummy, an example
923also used for testing.