blob: f15f46b788b36a652d1984ee1c28d39b7f5b1ae4 [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
145 Move cursor to the line number requested and make that line visible.
Georg Brandl116aa622007-08-15 14:28:22 +0000146
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500147Show Completions
148 Open a scrollable list allowing selection of keywords and attributes. See
Cheryl Sabella01421be2018-12-20 00:38:54 -0500149 :ref:`Completions <completions>` in the Editing and navigation section below.
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500150
151Expand Word
152 Expand a prefix you have typed to match a full word in the same window;
153 repeat to get a different expansion.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200154
155Show call tip
156 After an unclosed parenthesis for a function, open a small window with
Cheryl Sabella01421be2018-12-20 00:38:54 -0500157 function parameter hints. See :ref:`Calltips <calltips>` in the
158 Editing and navigation section below.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200159
160Show surrounding parens
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500161 Highlight the surrounding parenthesis.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200162
Terry Jan Reedy292cd6e2018-12-20 06:06:29 -0500163.. _format-menu:
164
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200165Format menu (Editor window only)
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500166^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200167
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500168Indent Region
169 Shift selected lines right by the indent width (default 4 spaces).
Georg Brandl116aa622007-08-15 14:28:22 +0000170
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500171Dedent Region
172 Shift selected lines left by the indent width (default 4 spaces).
Georg Brandl116aa622007-08-15 14:28:22 +0000173
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500174Comment Out Region
175 Insert ## in front of selected lines.
Georg Brandl116aa622007-08-15 14:28:22 +0000176
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500177Uncomment Region
178 Remove leading # or ## from selected lines.
Georg Brandl116aa622007-08-15 14:28:22 +0000179
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500180Tabify Region
181 Turn *leading* stretches of spaces into tabs. (Note: We recommend using
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200182 4 space blocks to indent Python code.)
Georg Brandl116aa622007-08-15 14:28:22 +0000183
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500184Untabify Region
185 Turn *all* tabs into the correct number of spaces.
Georg Brandl116aa622007-08-15 14:28:22 +0000186
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500187Toggle Tabs
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200188 Open a dialog to switch between indenting with spaces and tabs.
189
190New Indent Width
191 Open a dialog to change indent width. The accepted default by the Python
192 community is 4 spaces.
Georg Brandl116aa622007-08-15 14:28:22 +0000193
194Format Paragraph
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500195 Reformat the current blank-line-delimited paragraph in comment block or
196 multiline string or selected line in a string. All lines in the
197 paragraph will be formatted to less than N columns, where N defaults to 72.
Georg Brandl116aa622007-08-15 14:28:22 +0000198
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200199Strip trailing whitespace
Terry Jan Reedyff702892017-09-15 13:05:28 -0400200 Remove trailing space and other whitespace characters after the last
201 non-whitespace character of a line by applying str.rstrip to each line,
Terry Jan Reedy6bf644e2019-11-24 16:29:29 -0500202 including lines within multiline strings. Except for Shell windows,
203 remove extra newlines at the end of the file.
Georg Brandl116aa622007-08-15 14:28:22 +0000204
205.. index::
Georg Brandl116aa622007-08-15 14:28:22 +0000206 single: Run script
207
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200208Run menu (Editor window only)
209^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +0000210
Cheryl Sabella201bc2d2019-06-17 22:24:10 -0400211.. _run-module:
212
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500213Run Module
Cheryl Sabella201bc2d2019-06-17 22:24:10 -0400214 Do :ref:`Check Module <check-module>`. 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
Cheryl Sabella201bc2d2019-06-17 22:24:10 -0400222.. _run-custom:
223
224Run... Customized
225 Same as :ref:`Run Module <run-module>`, but run the module with customized
226 settings. *Command Line Arguments* extend :data:`sys.argv` as if passed
227 on a command line. The module can be run in the Shell without restarting.
228
Terry Jan Reedy14070292019-08-04 16:45:15 -0400229.. _check-module:
230
231Check Module
232 Check the syntax of the module currently open in the Editor window. If the
233 module has not been saved IDLE will either prompt the user to save or
234 autosave, as selected in the General tab of the Idle Settings dialog. If
235 there is a syntax error, the approximate location is indicated in the
236 Editor window.
237
238.. _python-shell:
239
240Python Shell
241 Open or wake up the Python Shell window.
242
Cheryl Sabella201bc2d2019-06-17 22:24:10 -0400243
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200244Shell menu (Shell window only)
245^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Ned Deily2778d0d2012-10-20 13:25:34 -0700246
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200247View Last Restart
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500248 Scroll the shell window to the last Shell restart.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200249
250Restart Shell
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500251 Restart the shell to clean the environment.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200252
Cheryl Sabellac0381aa2018-12-28 15:11:30 -0500253Previous History
254 Cycle through earlier commands in history which match the current entry.
255
256Next History
257 Cycle through later commands in history which match the current entry.
258
Terry Jan Reedy4b736762016-09-12 01:50:03 -0400259Interrupt Execution
260 Stop a running program.
261
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200262Debug menu (Shell window only)
263^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +0000264
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500265Go to File/Line
266 Look on the current line. with the cursor, and the line above for a filename
267 and line number. If found, open the file if not already open, and show the
268 line. Use this to view source lines referenced in an exception traceback
269 and lines found by Find in Files. Also available in the context menu of
270 the Shell window and Output windows.
Georg Brandl116aa622007-08-15 14:28:22 +0000271
272.. index::
Georg Brandl116aa622007-08-15 14:28:22 +0000273 single: debugger
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500274 single: stack viewer
275
276Debugger (toggle)
csabella9dc2b382017-04-29 18:28:36 -0400277 When activated, code entered in the Shell or run from an Editor will run
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500278 under the debugger. In the Editor, breakpoints can be set with the context
279 menu. This feature is still incomplete and somewhat experimental.
280
281Stack Viewer
282 Show the stack traceback of the last exception in a tree widget, with
283 access to locals and globals.
284
285Auto-open Stack Viewer
286 Toggle automatically opening the stack viewer on an unhandled exception.
Georg Brandl116aa622007-08-15 14:28:22 +0000287
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200288Options menu (Shell and Editor)
289^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +0000290
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200291Configure IDLE
Terry Jan Reedy93f35422015-10-13 22:03:51 -0400292 Open a configuration dialog and change preferences for the following:
293 fonts, indentation, keybindings, text color themes, startup windows and
Tal Einat7123ea02019-07-23 15:22:11 +0300294 size, additional help sources, and extensions. On macOS, open the
Terry Jan Reedy292cd6e2018-12-20 06:06:29 -0500295 configuration dialog by selecting Preferences in the application
Tal Einat7123ea02019-07-23 15:22:11 +0300296 menu. For more details, see
Terry Jan Reedy292cd6e2018-12-20 06:06:29 -0500297 :ref:`Setting preferences <preferences>` under Help and preferences.
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500298
Terry Jan Reedy14070292019-08-04 16:45:15 -0400299Most configuration options apply to all windows or all future windows.
300The option items below only apply to the active window.
Tal Einat7123ea02019-07-23 15:22:11 +0300301
Cheryl Sabellac1b4b0f2018-12-22 01:25:45 -0500302Show/Hide Code Context (Editor Window only)
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200303 Open a pane at the top of the edit window which shows the block context
Cheryl Sabella01421be2018-12-20 00:38:54 -0500304 of the code which has scrolled above the top of the window. See
Tal Einat7123ea02019-07-23 15:22:11 +0300305 :ref:`Code Context <code-context>` in the Editing and Navigation section
306 below.
307
308Show/Hide Line Numbers (Editor Window only)
309 Open a column to the left of the edit window which shows the number
310 of each line of text. The default is off, which may be changed in the
311 preferences (see :ref:`Setting preferences <preferences>`).
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200312
Terry Jan Reedydf9b0322019-05-27 19:16:46 -0400313Zoom/Restore Height
314 Toggles the window between normal size and maximum height. The initial size
315 defaults to 40 lines by 80 chars unless changed on the General tab of the
Tal Einat5bff3c82019-06-17 22:41:00 +0300316 Configure IDLE dialog. The maximum height for a screen is determined by
317 momentarily maximizing a window the first time one is zoomed on the screen.
Tal Einat7123ea02019-07-23 15:22:11 +0300318 Changing screen settings may invalidate the saved height. This toggle has
Tal Einat5bff3c82019-06-17 22:41:00 +0300319 no effect when a window is maximized.
Terry Jan Reedydf9b0322019-05-27 19:16:46 -0400320
Ned Deilyccb416f2015-01-17 21:06:27 -0800321Window menu (Shell and Editor)
322^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200323
Cheryl Sabellac1b4b0f2018-12-22 01:25:45 -0500324Lists the names of all open windows; select one to bring it to the foreground
325(deiconifying it if necessary).
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200326
327Help menu (Shell and Editor)
328^^^^^^^^^^^^^^^^^^^^^^^^^^^^
329
330About IDLE
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500331 Display version, copyright, license, credits, and more.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200332
333IDLE Help
Terry Jan Reedy18032632018-10-28 16:21:18 -0400334 Display this IDLE document, detailing the menu options, basic editing and
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200335 navigation, and other tips.
336
337Python Docs
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500338 Access local Python documentation, if installed, or start a web browser
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200339 and open docs.python.org showing the latest Python documentation.
340
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500341Turtle Demo
Andrés Delfino271818f2018-09-14 14:13:09 -0300342 Run the turtledemo module with example Python code and turtle drawings.
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500343
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200344Additional help sources may be added here with the Configure IDLE dialog under
Cheryl Sabella01421be2018-12-20 00:38:54 -0500345the General tab. See the :ref:`Help sources <help-sources>` subsection below
346for more on Help menu choices.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200347
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500348.. index::
349 single: Cut
350 single: Copy
351 single: Paste
352 single: Set Breakpoint
353 single: Clear Breakpoint
354 single: breakpoints
355
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500356Context Menus
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200357^^^^^^^^^^^^^^^^^^^^^^^^^^
358
Terry Jan Reedyb65413b2018-11-15 13:15:13 -0500359Open a context menu by right-clicking in a window (Control-click on macOS).
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500360Context menus have the standard clipboard functions also on the Edit menu.
Ned Deily2778d0d2012-10-20 13:25:34 -0700361
Andrew Svetlovd1837672012-11-01 22:41:19 +0200362Cut
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500363 Copy selection into the system-wide clipboard; then delete the selection.
Andrew Svetlovd1837672012-11-01 22:41:19 +0200364
365Copy
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500366 Copy selection into the system-wide clipboard.
Andrew Svetlovd1837672012-11-01 22:41:19 +0200367
368Paste
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500369 Insert contents of the system-wide clipboard into the current window.
370
371Editor windows also have breakpoint functions. Lines with a breakpoint set are
372specially marked. Breakpoints only have an effect when running under the
Tal Einatd6c08db2020-01-06 01:51:48 +0200373debugger. Breakpoints for a file are saved in the user's ``.idlerc``
374directory.
Andrew Svetlovd1837672012-11-01 22:41:19 +0200375
Ned Deily2778d0d2012-10-20 13:25:34 -0700376Set Breakpoint
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500377 Set a breakpoint on the current line.
Ned Deily2778d0d2012-10-20 13:25:34 -0700378
379Clear Breakpoint
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500380 Clear the breakpoint on that line.
Ned Deily2778d0d2012-10-20 13:25:34 -0700381
Terry Jan Reedy68d6dc02018-10-28 12:44:44 -0400382Shell and Output windows also have the following.
Andrew Svetlovd1837672012-11-01 22:41:19 +0200383
Ned Deily2778d0d2012-10-20 13:25:34 -0700384Go to file/line
385 Same as in Debug menu.
386
Benjamin Peterson577277f2019-03-25 21:46:35 -0700387The Shell window also has an output squeezing facility explained in the *Python
388Shell window* subsection below.
Terry Jan Reedy68d6dc02018-10-28 12:44:44 -0400389
390Squeeze
391 If the cursor is over an output line, squeeze all the output between
392 the code above and the prompt below down to a 'Squeezed text' label.
393
Ned Deily2778d0d2012-10-20 13:25:34 -0700394
Cheryl Sabella01421be2018-12-20 00:38:54 -0500395.. _editing-and-navigation:
396
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200397Editing and navigation
398----------------------
Georg Brandl116aa622007-08-15 14:28:22 +0000399
Terry Jan Reedyea9c8bd2018-10-28 20:42:18 -0400400Editor windows
401^^^^^^^^^^^^^^
402
403IDLE may open editor windows when it starts, depending on settings
404and how you start IDLE. Thereafter, use the File menu. There can be only
405one open editor window for a given file.
406
407The title bar contains the name of the file, the full path, and the version
408of Python and IDLE running the window. The status bar contains the line
409number ('Ln') and column number ('Col'). Line numbers start with 1;
410column numbers with 0.
411
412IDLE assumes that files with a known .py* extension contain Python code
413and that other files do not. Run Python code with the Run menu.
414
415Key bindings
416^^^^^^^^^^^^
417
Serhiy Storchaka0424eaf2015-09-12 17:45:25 +0300418In this section, 'C' refers to the :kbd:`Control` key on Windows and Unix and
Terry Jan Reedyb65413b2018-11-15 13:15:13 -0500419the :kbd:`Command` key on macOS.
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500420
Georg Brandl116aa622007-08-15 14:28:22 +0000421* :kbd:`Backspace` deletes to the left; :kbd:`Del` deletes to the right
422
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200423* :kbd:`C-Backspace` delete word left; :kbd:`C-Del` delete word to the right
424
Georg Brandl116aa622007-08-15 14:28:22 +0000425* Arrow keys and :kbd:`Page Up`/:kbd:`Page Down` to move around
426
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200427* :kbd:`C-LeftArrow` and :kbd:`C-RightArrow` moves by words
428
Georg Brandl116aa622007-08-15 14:28:22 +0000429* :kbd:`Home`/:kbd:`End` go to begin/end of line
430
431* :kbd:`C-Home`/:kbd:`C-End` go to begin/end of file
432
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200433* Some useful Emacs bindings are inherited from Tcl/Tk:
434
435 * :kbd:`C-a` beginning of line
436
437 * :kbd:`C-e` end of line
438
439 * :kbd:`C-k` kill line (but doesn't put it in clipboard)
440
441 * :kbd:`C-l` center window around the insertion point
442
csabella9dc2b382017-04-29 18:28:36 -0400443 * :kbd:`C-b` go backward one character without deleting (usually you can
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200444 also use the cursor key for this)
445
446 * :kbd:`C-f` go forward one character without deleting (usually you can
447 also use the cursor key for this)
448
449 * :kbd:`C-p` go up one line (usually you can also use the cursor key for
450 this)
451
452 * :kbd:`C-d` delete next character
453
454Standard keybindings (like :kbd:`C-c` to copy and :kbd:`C-v` to paste)
455may work. Keybindings are selected in the Configure IDLE dialog.
Georg Brandl116aa622007-08-15 14:28:22 +0000456
Georg Brandl116aa622007-08-15 14:28:22 +0000457Automatic indentation
458^^^^^^^^^^^^^^^^^^^^^
459
460After a block-opening statement, the next line is indented by 4 spaces (in the
461Python Shell window by one tab). After certain keywords (break, return etc.)
462the next line is dedented. In leading indentation, :kbd:`Backspace` deletes up
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200463to 4 spaces if they are there. :kbd:`Tab` inserts spaces (in the Python
csabella9dc2b382017-04-29 18:28:36 -0400464Shell window one tab), number depends on Indent width. Currently, tabs
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200465are restricted to four spaces due to Tcl/Tk limitations.
Georg Brandl116aa622007-08-15 14:28:22 +0000466
Terry Jan Reedy292cd6e2018-12-20 06:06:29 -0500467See also the indent/dedent region commands on the
468:ref:`Format menu <format-menu>`.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200469
Cheryl Sabella01421be2018-12-20 00:38:54 -0500470
471.. _completions:
472
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200473Completions
474^^^^^^^^^^^
475
476Completions are supplied for functions, classes, and attributes of classes,
477both built-in and user-defined. Completions are also provided for
478filenames.
479
480The AutoCompleteWindow (ACW) will open after a predefined delay (default is
481two seconds) after a '.' or (in a string) an os.sep is typed. If after one
482of those characters (plus zero or more other characters) a tab is typed
483the ACW will open immediately if a possible continuation is found.
484
485If there is only one possible completion for the characters entered, a
486:kbd:`Tab` will supply that completion without opening the ACW.
487
488'Show Completions' will force open a completions window, by default the
489:kbd:`C-space` will open a completions window. In an empty
490string, this will contain the files in the current directory. On a
491blank line, it will contain the built-in and user-defined functions and
csabella9dc2b382017-04-29 18:28:36 -0400492classes in the current namespaces, plus any modules imported. If some
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200493characters have been entered, the ACW will attempt to be more specific.
494
495If a string of characters is typed, the ACW selection will jump to the
496entry most closely matching those characters. Entering a :kbd:`tab` will
497cause the longest non-ambiguous match to be entered in the Editor window or
498Shell. Two :kbd:`tab` in a row will supply the current ACW selection, as
499will return or a double click. Cursor keys, Page Up/Down, mouse selection,
500and the scroll wheel all operate on the ACW.
501
502"Hidden" attributes can be accessed by typing the beginning of hidden
503name after a '.', e.g. '_'. This allows access to modules with
504``__all__`` set, or to class-private attributes.
505
506Completions and the 'Expand Word' facility can save a lot of typing!
507
508Completions are currently limited to those in the namespaces. Names in
509an Editor window which are not via ``__main__`` and :data:`sys.modules` will
510not be found. Run the module once with your imports to correct this situation.
511Note that IDLE itself places quite a few modules in sys.modules, so
512much can be found by default, e.g. the re module.
513
514If you don't like the ACW popping up unbidden, simply make the delay
Terry Jan Reedy37f81352015-09-29 01:55:57 -0400515longer or disable the extension.
516
Cheryl Sabella01421be2018-12-20 00:38:54 -0500517.. _calltips:
518
Terry Jan Reedy37f81352015-09-29 01:55:57 -0400519Calltips
520^^^^^^^^
521
Alex Gaynor1cf2a802017-02-28 22:26:56 -0500522A calltip is shown when one types :kbd:`(` after the name of an *accessible*
Terry Jan Reedy37f81352015-09-29 01:55:57 -0400523function. A name expression may include dots and subscripts. A calltip
524remains until it is clicked, the cursor is moved out of the argument area,
525or :kbd:`)` is typed. When the cursor is in the argument part of a definition,
526the menu or shortcut display a calltip.
527
528A calltip consists of the function signature and the first line of the
529docstring. For builtins without an accessible signature, the calltip
530consists of all lines up the fifth line or the first blank line. These
531details may change.
532
533The set of *accessible* functions depends on what modules have been imported
534into the user process, including those imported by Idle itself,
535and what definitions have been run, all since the last restart.
536
537For example, restart the Shell and enter ``itertools.count(``. A calltip
538appears because Idle imports itertools into the user process for its own use.
539(This could change.) Enter ``turtle.write(`` and nothing appears. Idle does
540not import turtle. The menu or shortcut do nothing either. Enter
541``import turtle`` and then ``turtle.write(`` will work.
542
543In an editor, import statements have no effect until one runs the file. One
544might want to run a file after writing the import statements at the top,
545or immediately run an existing file before editing.
Georg Brandl116aa622007-08-15 14:28:22 +0000546
Cheryl Sabella01421be2018-12-20 00:38:54 -0500547.. _code-context:
548
549Code Context
550^^^^^^^^^^^^
551
552Within an editor window containing Python code, code context can be toggled
553in order to show or hide a pane at the top of the window. When shown, this
554pane freezes the opening lines for block code, such as those beginning with
555``class``, ``def``, or ``if`` keywords, that would have otherwise scrolled
556out of view. The size of the pane will be expanded and contracted as needed
557to show the all current levels of context, up to the maximum number of
558lines defined in the Configure IDLE dialog (which defaults to 15). If there
559are no current context lines and the feature is toggled on, a single blank
560line will display. Clicking on a line in the context pane will move that
561line to the top of the editor.
562
563The text and background colors for the context pane can be configured under
564the Highlights tab in the Configure IDLE dialog.
565
Georg Brandl116aa622007-08-15 14:28:22 +0000566Python Shell window
567^^^^^^^^^^^^^^^^^^^
568
Terry Jan Reedy75d9d592018-11-06 12:37:36 -0500569With IDLE's Shell, one enters, edits, and recalls complete statements.
570Most consoles and terminals only work with a single physical line at a time.
571
572When one pastes code into Shell, it is not compiled and possibly executed
573until one hits :kbd:`Return`. One may edit pasted code first.
574If one pastes more that one statement into Shell, the result will be a
575:exc:`SyntaxError` when multiple statements are compiled as if they were one.
576
577The editing features described in previous subsections work when entering
578code interactively. IDLE's Shell window also responds to the following keys.
Terry Jan Reedy68d6dc02018-10-28 12:44:44 -0400579
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200580* :kbd:`C-c` interrupts executing command
Georg Brandl116aa622007-08-15 14:28:22 +0000581
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200582* :kbd:`C-d` sends end-of-file; closes window if typed at a ``>>>`` prompt
Georg Brandl116aa622007-08-15 14:28:22 +0000583
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200584* :kbd:`Alt-/` (Expand word) is also useful to reduce typing
Georg Brandl116aa622007-08-15 14:28:22 +0000585
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200586 Command history
Georg Brandl116aa622007-08-15 14:28:22 +0000587
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200588 * :kbd:`Alt-p` retrieves previous command matching what you have typed. On
Terry Jan Reedyb65413b2018-11-15 13:15:13 -0500589 macOS use :kbd:`C-p`.
Georg Brandl116aa622007-08-15 14:28:22 +0000590
Terry Jan Reedyb65413b2018-11-15 13:15:13 -0500591 * :kbd:`Alt-n` retrieves next. On macOS use :kbd:`C-n`.
Georg Brandl116aa622007-08-15 14:28:22 +0000592
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200593 * :kbd:`Return` while on any previous command retrieves that command
Georg Brandl116aa622007-08-15 14:28:22 +0000594
Terry Jan Reedyf660ce22015-09-24 23:13:49 -0400595Text colors
596^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +0000597
Terry Jan Reedyf660ce22015-09-24 23:13:49 -0400598Idle defaults to black on white text, but colors text with special meanings.
599For the shell, these are shell output, shell error, user output, and
600user error. For Python code, at the shell prompt or in an editor, these are
601keywords, builtin class and function names, names following ``class`` and
602``def``, strings, and comments. For any text window, these are the cursor (when
603present), found text (when possible), and selected text.
Georg Brandl116aa622007-08-15 14:28:22 +0000604
Terry Jan Reedyf660ce22015-09-24 23:13:49 -0400605Text coloring is done in the background, so uncolorized text is occasionally
606visible. To change the color scheme, use the Configure IDLE dialog
607Highlighting tab. The marking of debugger breakpoint lines in the editor and
608text in popups and dialogs is not user-configurable.
Georg Brandl116aa622007-08-15 14:28:22 +0000609
610
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400611Startup and code execution
612--------------------------
Benjamin Petersonf07d0022009-03-21 17:31:58 +0000613
614Upon startup with the ``-s`` option, IDLE will execute the file referenced by
615the environment variables :envvar:`IDLESTARTUP` or :envvar:`PYTHONSTARTUP`.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200616IDLE first checks for ``IDLESTARTUP``; if ``IDLESTARTUP`` is present the file
617referenced is run. If ``IDLESTARTUP`` is not present, IDLE checks for
Benjamin Petersonf07d0022009-03-21 17:31:58 +0000618``PYTHONSTARTUP``. Files referenced by these environment variables are
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200619convenient places to store functions that are used frequently from the IDLE
Benjamin Petersonf07d0022009-03-21 17:31:58 +0000620shell, or for executing import statements to import common modules.
621
622In addition, ``Tk`` also loads a startup file if it is present. Note that the
623Tk file is loaded unconditionally. This additional file is ``.Idle.py`` and is
624looked for in the user's home directory. Statements in this file will be
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500625executed in the Tk namespace, so this file is not useful for importing
626functions to be used from IDLE's Python shell.
Benjamin Petersonf07d0022009-03-21 17:31:58 +0000627
Georg Brandl116aa622007-08-15 14:28:22 +0000628Command line usage
629^^^^^^^^^^^^^^^^^^
630
Martin Panter1050d2d2016-07-26 11:18:21 +0200631.. code-block:: none
Georg Brandl116aa622007-08-15 14:28:22 +0000632
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400633 idle.py [-c command] [-d] [-e] [-h] [-i] [-r file] [-s] [-t title] [-] [arg] ...
Georg Brandl116aa622007-08-15 14:28:22 +0000634
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400635 -c command run command in the shell window
636 -d enable debugger and open shell window
637 -e open editor window
Terry Jan Reedy3399e1e2016-08-30 16:58:01 -0400638 -h print help message with legal combinations and exit
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400639 -i open shell window
640 -r file run file in shell window
641 -s run $IDLESTARTUP or $PYTHONSTARTUP first, in shell window
Georg Brandl116aa622007-08-15 14:28:22 +0000642 -t title set title of shell window
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400643 - run stdin in shell (- must be last option before args)
Georg Brandl116aa622007-08-15 14:28:22 +0000644
645If there are arguments:
646
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400647* If ``-``, ``-c``, or ``r`` is used, all arguments are placed in
648 ``sys.argv[1:...]`` and ``sys.argv[0]`` is set to ``''``, ``'-c'``,
649 or ``'-r'``. No editor window is opened, even if that is the default
650 set in the Options dialog.
Georg Brandl116aa622007-08-15 14:28:22 +0000651
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400652* Otherwise, arguments are files opened for editing and
653 ``sys.argv`` reflects the arguments passed to IDLE itself.
Georg Brandl116aa622007-08-15 14:28:22 +0000654
terryjreedy188aedf2017-06-13 21:32:16 -0400655Startup failure
656^^^^^^^^^^^^^^^
657
658IDLE uses a socket to communicate between the IDLE GUI process and the user
659code execution process. A connection must be established whenever the Shell
660starts or restarts. (The latter is indicated by a divider line that says
661'RESTART'). If the user process fails to connect to the GUI process, it
662displays a ``Tk`` error box with a 'cannot connect' message that directs the
663user here. It then exits.
664
665A common cause of failure is a user-written file with the same name as a
666standard library module, such as *random.py* and *tkinter.py*. When such a
667file is located in the same directory as a file that is about to be run,
668IDLE cannot import the stdlib file. The current fix is to rename the
669user file.
670
671Though less common than in the past, an antivirus or firewall program may
672stop the connection. If the program cannot be taught to allow the
673connection, then it must be turned off for IDLE to work. It is safe to
674allow this internal connection because no data is visible on external
675ports. A similar problem is a network mis-configuration that blocks
676connections.
677
678Python installation issues occasionally stop IDLE: multiple versions can
679clash, or a single installation might need admin access. If one undo the
680clash, or cannot or does not want to run as admin, it might be easiest to
681completely remove Python and start over.
682
683A zombie pythonw.exe process could be a problem. On Windows, use Task
684Manager to detect and stop one. Sometimes a restart initiated by a program
685crash or Keyboard Interrupt (control-C) may fail to connect. Dismissing
686the error box or Restart Shell on the Shell menu may fix a temporary problem.
687
688When IDLE first starts, it attempts to read user configuration files in
Tal Einatd6c08db2020-01-06 01:51:48 +0200689``~/.idlerc/`` (~ is one's home directory). If there is a problem, an error
terryjreedy188aedf2017-06-13 21:32:16 -0400690message should be displayed. Leaving aside random disk glitches, this can
691be prevented by never editing the files by hand, using the configuration
692dialog, under Options, instead Options. Once it happens, the solution may
693be to delete one or more of the configuration files.
694
695If IDLE quits with no message, and it was not started from a console, try
Tal Einatd6c08db2020-01-06 01:51:48 +0200696starting from a console (``python -m idlelib``) and see if a message appears.
terryjreedy188aedf2017-06-13 21:32:16 -0400697
Terry Jan Reedy5e790902018-11-05 21:30:32 -0500698Running user code
699^^^^^^^^^^^^^^^^^
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400700
Terry Jan Reedy98758bc2017-09-12 09:05:16 -0400701With rare exceptions, the result of executing Python code with IDLE is
Terry Jan Reedy5e790902018-11-05 21:30:32 -0500702intended to be the same as executing the same code by the default method,
703directly with Python in a text-mode system console or terminal window.
Terry Jan Reedy98758bc2017-09-12 09:05:16 -0400704However, the different interface and operation occasionally affect
Terry Jan Reedy5e790902018-11-05 21:30:32 -0500705visible results. For instance, ``sys.modules`` starts with more entries,
706and ``threading.activeCount()`` returns 2 instead of 1.
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400707
Terry Jan Reedy5e790902018-11-05 21:30:32 -0500708By default, IDLE runs user code in a separate OS process rather than in
709the user interface process that runs the shell and editor. In the execution
710process, it replaces ``sys.stdin``, ``sys.stdout``, and ``sys.stderr``
711with objects that get input from and send output to the Shell window.
712The original values stored in ``sys.__stdin__``, ``sys.__stdout__``, and
713``sys.__stderr__`` are not touched, but may be ``None``.
714
Terry Jan Reedy98758bc2017-09-12 09:05:16 -0400715When Shell has the focus, it controls the keyboard and screen. This is
716normally transparent, but functions that directly access the keyboard
Terry Jan Reedy5e790902018-11-05 21:30:32 -0500717and screen will not work. These include system-specific functions that
718determine whether a key has been pressed and if so, which.
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400719
Terry Jan Reedy5e790902018-11-05 21:30:32 -0500720IDLE's standard stream replacements are not inherited by subprocesses
721created in the execution process, whether directly by user code or by modules
722such as multiprocessing. If such subprocess use ``input`` from sys.stdin
723or ``print`` or ``write`` to sys.stdout or sys.stderr,
724IDLE should be started in a command line window. The secondary subprocess
725will then be attached to that window for input and output.
726
Tal Einatfcf1d002019-07-06 15:35:24 +0300727The IDLE code running in the execution process adds frames to the call stack
728that would not be there otherwise. IDLE wraps ``sys.getrecursionlimit`` and
729``sys.setrecursionlimit`` to reduce the effect of the additional stack frames.
730
Terry Jan Reedy5e790902018-11-05 21:30:32 -0500731If ``sys`` is reset by user code, such as with ``importlib.reload(sys)``,
732IDLE's changes are lost and input from the keyboard and output to the screen
733will not work correctly.
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400734
Terry Jan Reedy6d965b32019-05-19 22:52:22 -0400735When user code raises SystemExit either directly or by calling sys.exit, IDLE
736returns to a Shell prompt instead of exiting.
737
Terry Jan Reedy75d9d592018-11-06 12:37:36 -0500738User output in Shell
739^^^^^^^^^^^^^^^^^^^^
740
741When a program outputs text, the result is determined by the
742corresponding output device. When IDLE executes user code, ``sys.stdout``
743and ``sys.stderr`` are connected to the display area of IDLE's Shell. Some of
744its features are inherited from the underlying Tk Text widget. Others
Terry Jan Reedy76cd0c32018-11-06 23:55:06 -0500745are programmed additions. Where it matters, Shell is designed for development
746rather than production runs.
747
748For instance, Shell never throws away output. A program that sends unlimited
749output to Shell will eventually fill memory, resulting in a memory error.
750In contrast, some system text windows only keep the last n lines of output.
751A Windows console, for instance, keeps a user-settable 1 to 9999 lines,
752with 300 the default.
Terry Jan Reedy75d9d592018-11-06 12:37:36 -0500753
Benjamin Peterson577277f2019-03-25 21:46:35 -0700754A Tk Text widget, and hence IDLE's Shell, displays characters (codepoints) in
755the BMP (Basic Multilingual Plane) subset of Unicode. Which characters are
756displayed with a proper glyph and which with a replacement box depends on the
757operating system and installed fonts. Tab characters cause the following text
758to begin after the next tab stop. (They occur every 8 'characters'). Newline
759characters cause following text to appear on a new line. Other control
760characters are ignored or displayed as a space, box, or something else,
761depending on the operating system and font. (Moving the text cursor through
Terry Jan Reedy55d03512019-04-26 23:22:36 -0400762such output with arrow keys may exhibit some surprising spacing behavior.) ::
Terry Jan Reedy8a03ff22019-02-08 22:51:51 -0500763
Terry Jan Reedy55d03512019-04-26 23:22:36 -0400764 >>> s = 'a\tb\a<\x02><\r>\bc\nd' # Enter 22 chars.
Terry Jan Reedy8a03ff22019-02-08 22:51:51 -0500765 >>> len(s)
766 14
767 >>> s # Display repr(s)
768 'a\tb\x07<\x02><\r>\x08c\nd'
769 >>> print(s, end='') # Display s as is.
770 # Result varies by OS and font. Try it.
771
772The ``repr`` function is used for interactive echo of expression
773values. It returns an altered version of the input string in which
774control codes, some BMP codepoints, and all non-BMP codepoints are
775replaced with escape codes. As demonstrated above, it allows one to
776identify the characters in a string, regardless of how they are displayed.
Terry Jan Reedy75d9d592018-11-06 12:37:36 -0500777
778Normal and error output are generally kept separate (on separate lines)
779from code input and each other. They each get different highlight colors.
780
781For SyntaxError tracebacks, the normal '^' marking where the error was
782detected is replaced by coloring the text with an error highlight.
783When code run from a file causes other exceptions, one may right click
784on a traceback line to jump to the corresponding line in an IDLE editor.
785The file will be opened if necessary.
786
787Shell has a special facility for squeezing output lines down to a
788'Squeezed text' label. This is done automatically
789for output over N lines (N = 50 by default).
790N can be changed in the PyShell section of the General
791page of the Settings dialog. Output with fewer lines can be squeezed by
792right clicking on the output. This can be useful lines long enough to slow
793down scrolling.
794
795Squeezed output is expanded in place by double-clicking the label.
796It can also be sent to the clipboard or a separate view window by
797right-clicking the label.
798
Terry Jan Reedy98758bc2017-09-12 09:05:16 -0400799Developing tkinter applications
800^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
801
802IDLE is intentionally different from standard Python in order to
803facilitate development of tkinter programs. Enter ``import tkinter as tk;
804root = tk.Tk()`` in standard Python and nothing appears. Enter the same
805in IDLE and a tk window appears. In standard Python, one must also enter
806``root.update()`` to see the window. IDLE does the equivalent in the
Terry Jan Reedy8a533ff2019-05-16 01:20:37 -0400807background, about 20 times a second, which is about every 50 milliseconds.
Terry Jan Reedy98758bc2017-09-12 09:05:16 -0400808Next enter ``b = tk.Button(root, text='button'); b.pack()``. Again,
809nothing visibly changes in standard Python until one enters ``root.update()``.
810
811Most tkinter programs run ``root.mainloop()``, which usually does not
812return until the tk app is destroyed. If the program is run with
813``python -i`` or from an IDLE editor, a ``>>>`` shell prompt does not
814appear until ``mainloop()`` returns, at which time there is nothing left
815to interact with.
816
817When running a tkinter program from an IDLE editor, one can comment out
818the mainloop call. One then gets a shell prompt immediately and can
819interact with the live application. One just has to remember to
820re-enable the mainloop call when running in standard Python.
821
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500822Running without a subprocess
823^^^^^^^^^^^^^^^^^^^^^^^^^^^^
824
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400825By default, IDLE executes user code in a separate subprocess via a socket,
Terry Jan Reedy6e10ec52015-09-23 20:00:33 -0400826which uses the internal loopback interface. This connection is not
827externally visible and no data is sent to or received from the Internet.
828If firewall software complains anyway, you can ignore it.
829
830If the attempt to make the socket connection fails, Idle will notify you.
831Such failures are sometimes transient, but if persistent, the problem
csabella9dc2b382017-04-29 18:28:36 -0400832may be either a firewall blocking the connection or misconfiguration of
Terry Jan Reedy6e10ec52015-09-23 20:00:33 -0400833a particular system. Until the problem is fixed, one can run Idle with
834the -n command line switch.
835
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500836If IDLE is started with the -n command line switch it will run in a
837single process and will not create the subprocess which runs the RPC
838Python execution server. This can be useful if Python cannot create
839the subprocess or the RPC socket interface on your platform. However,
840in this mode user code is not isolated from IDLE itself. Also, the
841environment is not restarted when Run/Run Module (F5) is selected. If
842your code has been modified, you must reload() the affected modules and
843re-import any specific items (e.g. from foo import baz) if the changes
844are to take effect. For these reasons, it is preferable to run IDLE
845with the default subprocess if at all possible.
846
847.. deprecated:: 3.4
848
Georg Brandl116aa622007-08-15 14:28:22 +0000849
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500850Help and preferences
851--------------------
852
Cheryl Sabella01421be2018-12-20 00:38:54 -0500853.. _help-sources:
854
Terry Jan Reedy18032632018-10-28 16:21:18 -0400855Help sources
856^^^^^^^^^^^^
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200857
Terry Jan Reedy18032632018-10-28 16:21:18 -0400858Help menu entry "IDLE Help" displays a formatted html version of the
859IDLE chapter of the Library Reference. The result, in a read-only
860tkinter text window, is close to what one sees in a web browser.
861Navigate through the text with a mousewheel,
862the scrollbar, or up and down arrow keys held down.
863Or click the TOC (Table of Contents) button and select a section
864header in the opened box.
865
866Help menu entry "Python Docs" opens the extensive sources of help,
Tal Einatd6c08db2020-01-06 01:51:48 +0200867including tutorials, available at ``docs.python.org/x.y``, where 'x.y'
Terry Jan Reedy18032632018-10-28 16:21:18 -0400868is the currently running Python version. If your system
869has an off-line copy of the docs (this may be an installation option),
870that will be opened instead.
871
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200872Selected URLs can be added or removed from the help menu at any time using the
Tal Einatd6c08db2020-01-06 01:51:48 +0200873General tab of the Configure IDLE dialog.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200874
Terry Jan Reedy292cd6e2018-12-20 06:06:29 -0500875.. _preferences:
876
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500877Setting preferences
878^^^^^^^^^^^^^^^^^^^
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200879
880The font preferences, highlighting, keys, and general preferences can be
Terry Jan Reedy292cd6e2018-12-20 06:06:29 -0500881changed via Configure IDLE on the Option menu.
Tal Einatd6c08db2020-01-06 01:51:48 +0200882Non-default user settings are saved in a ``.idlerc`` directory in the user's
Terry Jan Reedy292cd6e2018-12-20 06:06:29 -0500883home directory. Problems caused by bad user configuration files are solved
Tal Einatd6c08db2020-01-06 01:51:48 +0200884by editing or deleting one or more of the files in ``.idlerc``.
Terry Jan Reedy292cd6e2018-12-20 06:06:29 -0500885
Terry Jan Reedyd6101162019-02-23 23:04:53 -0500886On the Font tab, see the text sample for the effect of font face and size
887on multiple characters in multiple languages. Edit the sample to add
888other characters of personal interest. Use the sample to select
889monospaced fonts. If particular characters have problems in Shell or an
890editor, add them to the top of the sample and try changing first size
891and then font.
892
Terry Jan Reedy292cd6e2018-12-20 06:06:29 -0500893On the Highlights and Keys tab, select a built-in or custom color theme
894and key set. To use a newer built-in color theme or key set with older
895IDLEs, save it as a new custom theme or key set and it well be accessible
896to older IDLEs.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200897
Terry Jan Reedyb65413b2018-11-15 13:15:13 -0500898IDLE on macOS
Terry Jan Reedy50ff02b2018-11-10 23:26:31 -0500899^^^^^^^^^^^^^
900
901Under System Preferences: Dock, one can set "Prefer tabs when opening
902documents" to "Always". This setting is not compatible with the tk/tkinter
903GUI framework used by IDLE, and it breaks a few IDLE features.
904
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200905Extensions
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500906^^^^^^^^^^
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200907
csabella9dc2b382017-04-29 18:28:36 -0400908IDLE contains an extension facility. Preferences for extensions can be
Terry Jan Reedyadb4cd22017-09-12 07:45:15 -0400909changed with the Extensions tab of the preferences dialog. See the
910beginning of config-extensions.def in the idlelib directory for further
911information. The only current default extension is zzdummy, an example
912also used for testing.