blob: d6021042c611666519fe8bfd5197d0eba67f68de [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
Miss Islington (bot)5acaad02022-01-26 19:55:25 -080099Close Window
100 Close the current window (if an unsaved editor, ask to save; if an unsaved
101 Shell, ask to quit execution). Calling ``exit()`` or ``close()`` in the Shell
102 window also closes Shell. If this is the only window, also exit IDLE.
Georg Brandl116aa622007-08-15 14:28:22 +0000103
Miss Islington (bot)5acaad02022-01-26 19:55:25 -0800104Exit IDLE
105 Close all windows and quit IDLE (ask to save unsaved edit windows).
Georg Brandl116aa622007-08-15 14:28:22 +0000106
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200107Edit menu (Shell and Editor)
108^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +0000109
110Undo
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500111 Undo the last change to the current window. A maximum of 1000 changes may
112 be undone.
Georg Brandl116aa622007-08-15 14:28:22 +0000113
114Redo
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500115 Redo the last undone change to the current window.
Georg Brandl116aa622007-08-15 14:28:22 +0000116
117Cut
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500118 Copy selection into the system-wide clipboard; then delete the selection.
Georg Brandl116aa622007-08-15 14:28:22 +0000119
120Copy
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500121 Copy selection into the system-wide clipboard.
Georg Brandl116aa622007-08-15 14:28:22 +0000122
123Paste
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500124 Insert contents of the system-wide clipboard into the current window.
125
126The clipboard functions are also available in context menus.
Georg Brandl116aa622007-08-15 14:28:22 +0000127
128Select All
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500129 Select the entire contents of the current window.
Georg Brandl116aa622007-08-15 14:28:22 +0000130
131Find...
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500132 Open a search dialog with many options
Georg Brandl116aa622007-08-15 14:28:22 +0000133
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500134Find Again
135 Repeat the last search, if there is one.
Georg Brandl116aa622007-08-15 14:28:22 +0000136
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500137Find Selection
138 Search for the currently selected string, if there is one.
Georg Brandl116aa622007-08-15 14:28:22 +0000139
140Find in Files...
Serhiy Storchaka6a7b3a72016-04-17 08:32:47 +0300141 Open a file search dialog. Put results in a new output window.
Georg Brandl116aa622007-08-15 14:28:22 +0000142
143Replace...
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500144 Open a search-and-replace dialog.
Georg Brandl116aa622007-08-15 14:28:22 +0000145
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500146Go to Line
Terry Jan Reedy2522db12020-03-08 14:32:42 -0400147 Move the cursor to the beginning of the line requested and make that
148 line visible. A request past the end of the file goes to the end.
149 Clear any selection and update the line and column status.
Georg Brandl116aa622007-08-15 14:28:22 +0000150
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500151Show Completions
Terry Jan Reedybce2eb42020-07-09 18:08:33 -0400152 Open a scrollable list allowing selection of existing names. See
Cheryl Sabella01421be2018-12-20 00:38:54 -0500153 :ref:`Completions <completions>` in the Editing and navigation section below.
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500154
155Expand Word
156 Expand a prefix you have typed to match a full word in the same window;
157 repeat to get a different expansion.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200158
159Show call tip
160 After an unclosed parenthesis for a function, open a small window with
Cheryl Sabella01421be2018-12-20 00:38:54 -0500161 function parameter hints. See :ref:`Calltips <calltips>` in the
162 Editing and navigation section below.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200163
164Show surrounding parens
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500165 Highlight the surrounding parenthesis.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200166
Terry Jan Reedy292cd6e2018-12-20 06:06:29 -0500167.. _format-menu:
168
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200169Format menu (Editor window only)
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500170^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200171
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500172Indent Region
173 Shift selected lines right by the indent width (default 4 spaces).
Georg Brandl116aa622007-08-15 14:28:22 +0000174
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500175Dedent Region
176 Shift selected lines left by the indent width (default 4 spaces).
Georg Brandl116aa622007-08-15 14:28:22 +0000177
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500178Comment Out Region
179 Insert ## in front of selected lines.
Georg Brandl116aa622007-08-15 14:28:22 +0000180
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500181Uncomment Region
182 Remove leading # or ## from selected lines.
Georg Brandl116aa622007-08-15 14:28:22 +0000183
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500184Tabify Region
185 Turn *leading* stretches of spaces into tabs. (Note: We recommend using
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200186 4 space blocks to indent Python code.)
Georg Brandl116aa622007-08-15 14:28:22 +0000187
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500188Untabify Region
189 Turn *all* tabs into the correct number of spaces.
Georg Brandl116aa622007-08-15 14:28:22 +0000190
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500191Toggle Tabs
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200192 Open a dialog to switch between indenting with spaces and tabs.
193
194New Indent Width
195 Open a dialog to change indent width. The accepted default by the Python
196 community is 4 spaces.
Georg Brandl116aa622007-08-15 14:28:22 +0000197
198Format Paragraph
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500199 Reformat the current blank-line-delimited paragraph in comment block or
200 multiline string or selected line in a string. All lines in the
201 paragraph will be formatted to less than N columns, where N defaults to 72.
Georg Brandl116aa622007-08-15 14:28:22 +0000202
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200203Strip trailing whitespace
Terry Jan Reedyff702892017-09-15 13:05:28 -0400204 Remove trailing space and other whitespace characters after the last
205 non-whitespace character of a line by applying str.rstrip to each line,
Terry Jan Reedy6bf644e2019-11-24 16:29:29 -0500206 including lines within multiline strings. Except for Shell windows,
207 remove extra newlines at the end of the file.
Georg Brandl116aa622007-08-15 14:28:22 +0000208
209.. index::
Georg Brandl116aa622007-08-15 14:28:22 +0000210 single: Run script
211
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200212Run menu (Editor window only)
213^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +0000214
Cheryl Sabella201bc2d2019-06-17 22:24:10 -0400215.. _run-module:
216
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500217Run Module
Cheryl Sabella201bc2d2019-06-17 22:24:10 -0400218 Do :ref:`Check Module <check-module>`. If no error, restart the shell to clean the
Terry Jan Reedy8b5a9812015-09-24 01:39:30 -0400219 environment, then execute the module. Output is displayed in the Shell
220 window. Note that output requires use of ``print`` or ``write``.
221 When execution is complete, the Shell retains focus and displays a prompt.
222 At this point, one may interactively explore the result of execution.
223 This is similar to executing a file with ``python -i file`` at a command
224 line.
Georg Brandl116aa622007-08-15 14:28:22 +0000225
Cheryl Sabella201bc2d2019-06-17 22:24:10 -0400226.. _run-custom:
227
228Run... Customized
229 Same as :ref:`Run Module <run-module>`, but run the module with customized
230 settings. *Command Line Arguments* extend :data:`sys.argv` as if passed
231 on a command line. The module can be run in the Shell without restarting.
232
Terry Jan Reedy14070292019-08-04 16:45:15 -0400233.. _check-module:
234
235Check Module
236 Check the syntax of the module currently open in the Editor window. If the
237 module has not been saved IDLE will either prompt the user to save or
238 autosave, as selected in the General tab of the Idle Settings dialog. If
239 there is a syntax error, the approximate location is indicated in the
240 Editor window.
241
242.. _python-shell:
243
244Python Shell
245 Open or wake up the Python Shell window.
246
Cheryl Sabella201bc2d2019-06-17 22:24:10 -0400247
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200248Shell menu (Shell window only)
249^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Ned Deily2778d0d2012-10-20 13:25:34 -0700250
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200251View Last Restart
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500252 Scroll the shell window to the last Shell restart.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200253
254Restart Shell
Ken7a343802021-01-27 07:55:52 +0800255 Restart the shell to clean the environment and reset display and exception handling.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200256
Cheryl Sabellac0381aa2018-12-28 15:11:30 -0500257Previous History
258 Cycle through earlier commands in history which match the current entry.
259
260Next History
261 Cycle through later commands in history which match the current entry.
262
Terry Jan Reedy4b736762016-09-12 01:50:03 -0400263Interrupt Execution
264 Stop a running program.
265
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200266Debug menu (Shell window only)
267^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +0000268
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500269Go to File/Line
270 Look on the current line. with the cursor, and the line above for a filename
271 and line number. If found, open the file if not already open, and show the
272 line. Use this to view source lines referenced in an exception traceback
273 and lines found by Find in Files. Also available in the context menu of
274 the Shell window and Output windows.
Georg Brandl116aa622007-08-15 14:28:22 +0000275
276.. index::
Georg Brandl116aa622007-08-15 14:28:22 +0000277 single: debugger
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500278 single: stack viewer
279
280Debugger (toggle)
csabella9dc2b382017-04-29 18:28:36 -0400281 When activated, code entered in the Shell or run from an Editor will run
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500282 under the debugger. In the Editor, breakpoints can be set with the context
283 menu. This feature is still incomplete and somewhat experimental.
284
285Stack Viewer
286 Show the stack traceback of the last exception in a tree widget, with
287 access to locals and globals.
288
289Auto-open Stack Viewer
290 Toggle automatically opening the stack viewer on an unhandled exception.
Georg Brandl116aa622007-08-15 14:28:22 +0000291
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200292Options menu (Shell and Editor)
293^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +0000294
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200295Configure IDLE
Terry Jan Reedy93f35422015-10-13 22:03:51 -0400296 Open a configuration dialog and change preferences for the following:
297 fonts, indentation, keybindings, text color themes, startup windows and
Tal Einat7123ea02019-07-23 15:22:11 +0300298 size, additional help sources, and extensions. On macOS, open the
Terry Jan Reedy292cd6e2018-12-20 06:06:29 -0500299 configuration dialog by selecting Preferences in the application
Tal Einat7123ea02019-07-23 15:22:11 +0300300 menu. For more details, see
Terry Jan Reedy292cd6e2018-12-20 06:06:29 -0500301 :ref:`Setting preferences <preferences>` under Help and preferences.
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500302
Terry Jan Reedy14070292019-08-04 16:45:15 -0400303Most configuration options apply to all windows or all future windows.
304The option items below only apply to the active window.
Tal Einat7123ea02019-07-23 15:22:11 +0300305
Cheryl Sabellac1b4b0f2018-12-22 01:25:45 -0500306Show/Hide Code Context (Editor Window only)
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200307 Open a pane at the top of the edit window which shows the block context
Cheryl Sabella01421be2018-12-20 00:38:54 -0500308 of the code which has scrolled above the top of the window. See
Tal Einat7123ea02019-07-23 15:22:11 +0300309 :ref:`Code Context <code-context>` in the Editing and Navigation section
310 below.
311
312Show/Hide Line Numbers (Editor Window only)
313 Open a column to the left of the edit window which shows the number
314 of each line of text. The default is off, which may be changed in the
315 preferences (see :ref:`Setting preferences <preferences>`).
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200316
Terry Jan Reedydf9b0322019-05-27 19:16:46 -0400317Zoom/Restore Height
318 Toggles the window between normal size and maximum height. The initial size
319 defaults to 40 lines by 80 chars unless changed on the General tab of the
Tal Einat5bff3c82019-06-17 22:41:00 +0300320 Configure IDLE dialog. The maximum height for a screen is determined by
321 momentarily maximizing a window the first time one is zoomed on the screen.
Tal Einat7123ea02019-07-23 15:22:11 +0300322 Changing screen settings may invalidate the saved height. This toggle has
Tal Einat5bff3c82019-06-17 22:41:00 +0300323 no effect when a window is maximized.
Terry Jan Reedydf9b0322019-05-27 19:16:46 -0400324
Ned Deilyccb416f2015-01-17 21:06:27 -0800325Window menu (Shell and Editor)
326^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200327
Cheryl Sabellac1b4b0f2018-12-22 01:25:45 -0500328Lists the names of all open windows; select one to bring it to the foreground
329(deiconifying it if necessary).
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200330
331Help menu (Shell and Editor)
332^^^^^^^^^^^^^^^^^^^^^^^^^^^^
333
334About IDLE
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500335 Display version, copyright, license, credits, and more.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200336
337IDLE Help
Terry Jan Reedy18032632018-10-28 16:21:18 -0400338 Display this IDLE document, detailing the menu options, basic editing and
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200339 navigation, and other tips.
340
341Python Docs
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500342 Access local Python documentation, if installed, or start a web browser
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200343 and open docs.python.org showing the latest Python documentation.
344
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500345Turtle Demo
Andrés Delfino271818f2018-09-14 14:13:09 -0300346 Run the turtledemo module with example Python code and turtle drawings.
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500347
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200348Additional help sources may be added here with the Configure IDLE dialog under
Cheryl Sabella01421be2018-12-20 00:38:54 -0500349the General tab. See the :ref:`Help sources <help-sources>` subsection below
350for more on Help menu choices.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200351
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500352.. index::
353 single: Cut
354 single: Copy
355 single: Paste
356 single: Set Breakpoint
357 single: Clear Breakpoint
358 single: breakpoints
359
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500360Context Menus
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200361^^^^^^^^^^^^^^^^^^^^^^^^^^
362
Terry Jan Reedyb65413b2018-11-15 13:15:13 -0500363Open a context menu by right-clicking in a window (Control-click on macOS).
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500364Context menus have the standard clipboard functions also on the Edit menu.
Ned Deily2778d0d2012-10-20 13:25:34 -0700365
Andrew Svetlovd1837672012-11-01 22:41:19 +0200366Cut
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500367 Copy selection into the system-wide clipboard; then delete the selection.
Andrew Svetlovd1837672012-11-01 22:41:19 +0200368
369Copy
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500370 Copy selection into the system-wide clipboard.
Andrew Svetlovd1837672012-11-01 22:41:19 +0200371
372Paste
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500373 Insert contents of the system-wide clipboard into the current window.
374
375Editor windows also have breakpoint functions. Lines with a breakpoint set are
376specially marked. Breakpoints only have an effect when running under the
Tal Einatd6c08db2020-01-06 01:51:48 +0200377debugger. Breakpoints for a file are saved in the user's ``.idlerc``
378directory.
Andrew Svetlovd1837672012-11-01 22:41:19 +0200379
Ned Deily2778d0d2012-10-20 13:25:34 -0700380Set Breakpoint
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500381 Set a breakpoint on the current line.
Ned Deily2778d0d2012-10-20 13:25:34 -0700382
383Clear Breakpoint
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500384 Clear the breakpoint on that line.
Ned Deily2778d0d2012-10-20 13:25:34 -0700385
Terry Jan Reedy68d6dc02018-10-28 12:44:44 -0400386Shell and Output windows also have the following.
Andrew Svetlovd1837672012-11-01 22:41:19 +0200387
Ned Deily2778d0d2012-10-20 13:25:34 -0700388Go to file/line
389 Same as in Debug menu.
390
Benjamin Peterson577277f2019-03-25 21:46:35 -0700391The Shell window also has an output squeezing facility explained in the *Python
392Shell window* subsection below.
Terry Jan Reedy68d6dc02018-10-28 12:44:44 -0400393
394Squeeze
395 If the cursor is over an output line, squeeze all the output between
396 the code above and the prompt below down to a 'Squeezed text' label.
397
Ned Deily2778d0d2012-10-20 13:25:34 -0700398
Cheryl Sabella01421be2018-12-20 00:38:54 -0500399.. _editing-and-navigation:
400
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200401Editing and navigation
402----------------------
Georg Brandl116aa622007-08-15 14:28:22 +0000403
Terry Jan Reedyea9c8bd2018-10-28 20:42:18 -0400404Editor windows
405^^^^^^^^^^^^^^
406
407IDLE may open editor windows when it starts, depending on settings
408and how you start IDLE. Thereafter, use the File menu. There can be only
409one open editor window for a given file.
410
411The title bar contains the name of the file, the full path, and the version
412of Python and IDLE running the window. The status bar contains the line
413number ('Ln') and column number ('Col'). Line numbers start with 1;
414column numbers with 0.
415
416IDLE assumes that files with a known .py* extension contain Python code
417and that other files do not. Run Python code with the Run menu.
418
419Key bindings
420^^^^^^^^^^^^
421
Serhiy Storchaka0424eaf2015-09-12 17:45:25 +0300422In this section, 'C' refers to the :kbd:`Control` key on Windows and Unix and
Terry Jan Reedyb65413b2018-11-15 13:15:13 -0500423the :kbd:`Command` key on macOS.
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500424
Georg Brandl116aa622007-08-15 14:28:22 +0000425* :kbd:`Backspace` deletes to the left; :kbd:`Del` deletes to the right
426
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200427* :kbd:`C-Backspace` delete word left; :kbd:`C-Del` delete word to the right
428
Georg Brandl116aa622007-08-15 14:28:22 +0000429* Arrow keys and :kbd:`Page Up`/:kbd:`Page Down` to move around
430
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200431* :kbd:`C-LeftArrow` and :kbd:`C-RightArrow` moves by words
432
Georg Brandl116aa622007-08-15 14:28:22 +0000433* :kbd:`Home`/:kbd:`End` go to begin/end of line
434
435* :kbd:`C-Home`/:kbd:`C-End` go to begin/end of file
436
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200437* Some useful Emacs bindings are inherited from Tcl/Tk:
438
439 * :kbd:`C-a` beginning of line
440
441 * :kbd:`C-e` end of line
442
443 * :kbd:`C-k` kill line (but doesn't put it in clipboard)
444
445 * :kbd:`C-l` center window around the insertion point
446
csabella9dc2b382017-04-29 18:28:36 -0400447 * :kbd:`C-b` go backward one character without deleting (usually you can
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200448 also use the cursor key for this)
449
450 * :kbd:`C-f` go forward one character without deleting (usually you can
451 also use the cursor key for this)
452
453 * :kbd:`C-p` go up one line (usually you can also use the cursor key for
454 this)
455
456 * :kbd:`C-d` delete next character
457
458Standard keybindings (like :kbd:`C-c` to copy and :kbd:`C-v` to paste)
459may work. Keybindings are selected in the Configure IDLE dialog.
Georg Brandl116aa622007-08-15 14:28:22 +0000460
Georg Brandl116aa622007-08-15 14:28:22 +0000461Automatic indentation
462^^^^^^^^^^^^^^^^^^^^^
463
464After a block-opening statement, the next line is indented by 4 spaces (in the
465Python Shell window by one tab). After certain keywords (break, return etc.)
466the next line is dedented. In leading indentation, :kbd:`Backspace` deletes up
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200467to 4 spaces if they are there. :kbd:`Tab` inserts spaces (in the Python
csabella9dc2b382017-04-29 18:28:36 -0400468Shell window one tab), number depends on Indent width. Currently, tabs
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200469are restricted to four spaces due to Tcl/Tk limitations.
Georg Brandl116aa622007-08-15 14:28:22 +0000470
Terry Jan Reedy292cd6e2018-12-20 06:06:29 -0500471See also the indent/dedent region commands on the
472:ref:`Format menu <format-menu>`.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200473
Cheryl Sabella01421be2018-12-20 00:38:54 -0500474.. _completions:
475
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200476Completions
477^^^^^^^^^^^
478
Terry Jan Reedybce2eb42020-07-09 18:08:33 -0400479Completions are supplied, when requested and available, for module
480names, attributes of classes or functions, or filenames. Each request
481method displays a completion box with existing names. (See tab
482completions below for an exception.) For any box, change the name
483being completed and the item highlighted in the box by
484typing and deleting characters; by hitting :kbd:`Up`, :kbd:`Down`,
485:kbd:`PageUp`, :kbd:`PageDown`, :kbd:`Home`, and :kbd:`End` keys;
486and by a single click within the box. Close the box with :kbd:`Escape`,
487:kbd:`Enter`, and double :kbd:`Tab` keys or clicks outside the box.
488A double click within the box selects and closes.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200489
Terry Jan Reedybce2eb42020-07-09 18:08:33 -0400490One way to open a box is to type a key character and wait for a
491predefined interval. This defaults to 2 seconds; customize it
492in the settings dialog. (To prevent auto popups, set the delay to a
493large number of milliseconds, such as 100000000.) For imported module
494names or class or function attributes, type '.'.
495For filenames in the root directory, type :data:`os.sep` or
Andre Delfino7a797a32020-09-09 19:17:14 -0300496:data:`os.altsep` immediately after an opening quote. (On Windows,
Terry Jan Reedybce2eb42020-07-09 18:08:33 -0400497one can specify a drive first.) Move into subdirectories by typing a
498directory name and a separator.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200499
Terry Jan Reedybce2eb42020-07-09 18:08:33 -0400500Instead of waiting, or after a box is closed, open a completion box
501immediately with Show Completions on the Edit menu. The default hot
502key is :kbd:`C-space`. If one types a prefix for the desired name
503before opening the box, the first match or near miss is made visible.
504The result is the same as if one enters a prefix
505after the box is displayed. Show Completions after a quote completes
506filenames in the current directory instead of a root directory.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200507
Terry Jan Reedybce2eb42020-07-09 18:08:33 -0400508Hitting :kbd:`Tab` after a prefix usually has the same effect as Show
509Completions. (With no prefix, it indents.) However, if there is only
510one match to the prefix, that match is immediately added to the editor
511text without opening a box.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200512
Terry Jan Reedybce2eb42020-07-09 18:08:33 -0400513Invoking 'Show Completions', or hitting :kbd:`Tab` after a prefix,
514outside of a string and without a preceding '.' opens a box with
515keywords, builtin names, and available module-level names.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200516
Terry Jan Reedybce2eb42020-07-09 18:08:33 -0400517When editing code in an editor (as oppose to Shell), increase the
518available module-level names by running your code
519and not restarting the Shell thereafter. This is especially useful
520after adding imports at the top of a file. This also increases
521possible attribute completions.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200522
Miss Islington (bot)3390dfa2021-08-23 10:53:52 -0700523Completion boxes initially exclude names beginning with '_' or, for
Terry Jan Reedybce2eb42020-07-09 18:08:33 -0400524modules, not included in '__all__'. The hidden names can be accessed
525by typing '_' after '.', either before or after the box is opened.
Terry Jan Reedy37f81352015-09-29 01:55:57 -0400526
Cheryl Sabella01421be2018-12-20 00:38:54 -0500527.. _calltips:
528
Terry Jan Reedy37f81352015-09-29 01:55:57 -0400529Calltips
530^^^^^^^^
531
Terry Jan Reedy947adca2020-09-22 13:21:58 -0400532A calltip is shown automatically when one types :kbd:`(` after the name
533of an *accessible* function. A function name expression may include
534dots and subscripts. A calltip remains until it is clicked, the cursor
535is moved out of the argument area, or :kbd:`)` is typed. Whenever the
536cursor is in the argument part of a definition, select Edit and "Show
537Call Tip" on the menu or enter its shortcut to display a calltip.
Terry Jan Reedy37f81352015-09-29 01:55:57 -0400538
Terry Jan Reedy947adca2020-09-22 13:21:58 -0400539The calltip consists of the function's signature and docstring up to
540the latter's first blank line or the fifth non-blank line. (Some builtin
541functions lack an accessible signature.) A '/' or '*' in the signature
542indicates that the preceding or following arguments are passed by
543position or name (keyword) only. Details are subject to change.
Terry Jan Reedy37f81352015-09-29 01:55:57 -0400544
Terry Jan Reedy947adca2020-09-22 13:21:58 -0400545In Shell, the accessible functions depends on what modules have been
546imported into the user process, including those imported by Idle itself,
547and which definitions have been run, all since the last restart.
Terry Jan Reedy37f81352015-09-29 01:55:57 -0400548
549For example, restart the Shell and enter ``itertools.count(``. A calltip
Terry Jan Reedy947adca2020-09-22 13:21:58 -0400550appears because Idle imports itertools into the user process for its own
551use. (This could change.) Enter ``turtle.write(`` and nothing appears.
552Idle does not itself import turtle. The menu entry and shortcut also do
553nothing. Enter ``import turtle``. Thereafter, ``turtle.write(``
554will display a calltip.
Terry Jan Reedy37f81352015-09-29 01:55:57 -0400555
Terry Jan Reedy947adca2020-09-22 13:21:58 -0400556In an editor, import statements have no effect until one runs the file.
557One might want to run a file after writing import statements, after
558adding function definitions, or after opening an existing file.
Georg Brandl116aa622007-08-15 14:28:22 +0000559
Cheryl Sabella01421be2018-12-20 00:38:54 -0500560.. _code-context:
561
562Code Context
563^^^^^^^^^^^^
564
565Within an editor window containing Python code, code context can be toggled
566in order to show or hide a pane at the top of the window. When shown, this
567pane freezes the opening lines for block code, such as those beginning with
568``class``, ``def``, or ``if`` keywords, that would have otherwise scrolled
569out of view. The size of the pane will be expanded and contracted as needed
570to show the all current levels of context, up to the maximum number of
571lines defined in the Configure IDLE dialog (which defaults to 15). If there
572are no current context lines and the feature is toggled on, a single blank
573line will display. Clicking on a line in the context pane will move that
574line to the top of the editor.
575
576The text and background colors for the context pane can be configured under
577the Highlights tab in the Configure IDLE dialog.
578
Georg Brandl116aa622007-08-15 14:28:22 +0000579Python Shell window
580^^^^^^^^^^^^^^^^^^^
581
Terry Jan Reedy75d9d592018-11-06 12:37:36 -0500582With IDLE's Shell, one enters, edits, and recalls complete statements.
583Most consoles and terminals only work with a single physical line at a time.
584
585When one pastes code into Shell, it is not compiled and possibly executed
586until one hits :kbd:`Return`. One may edit pasted code first.
587If one pastes more that one statement into Shell, the result will be a
588:exc:`SyntaxError` when multiple statements are compiled as if they were one.
589
590The editing features described in previous subsections work when entering
591code interactively. IDLE's Shell window also responds to the following keys.
Terry Jan Reedy68d6dc02018-10-28 12:44:44 -0400592
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200593* :kbd:`C-c` interrupts executing command
Georg Brandl116aa622007-08-15 14:28:22 +0000594
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200595* :kbd:`C-d` sends end-of-file; closes window if typed at a ``>>>`` prompt
Georg Brandl116aa622007-08-15 14:28:22 +0000596
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200597* :kbd:`Alt-/` (Expand word) is also useful to reduce typing
Georg Brandl116aa622007-08-15 14:28:22 +0000598
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200599 Command history
Georg Brandl116aa622007-08-15 14:28:22 +0000600
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200601 * :kbd:`Alt-p` retrieves previous command matching what you have typed. On
Terry Jan Reedyb65413b2018-11-15 13:15:13 -0500602 macOS use :kbd:`C-p`.
Georg Brandl116aa622007-08-15 14:28:22 +0000603
Terry Jan Reedyb65413b2018-11-15 13:15:13 -0500604 * :kbd:`Alt-n` retrieves next. On macOS use :kbd:`C-n`.
Georg Brandl116aa622007-08-15 14:28:22 +0000605
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200606 * :kbd:`Return` while on any previous command retrieves that command
Georg Brandl116aa622007-08-15 14:28:22 +0000607
Terry Jan Reedyf660ce22015-09-24 23:13:49 -0400608Text colors
609^^^^^^^^^^^
Georg Brandl116aa622007-08-15 14:28:22 +0000610
Terry Jan Reedyf660ce22015-09-24 23:13:49 -0400611Idle defaults to black on white text, but colors text with special meanings.
612For the shell, these are shell output, shell error, user output, and
613user error. For Python code, at the shell prompt or in an editor, these are
614keywords, builtin class and function names, names following ``class`` and
615``def``, strings, and comments. For any text window, these are the cursor (when
616present), found text (when possible), and selected text.
Georg Brandl116aa622007-08-15 14:28:22 +0000617
Miss Islington (bot)33576042021-05-19 02:44:14 -0700618IDLE also highlights the :ref:`soft keywords <soft-keywords>` :keyword:`match`,
619:keyword:`case <match>`, and :keyword:`_ <wildcard-patterns>` in
620pattern-matching statements. However, this highlighting is not perfect and
621will be incorrect in some rare cases, including some ``_``-s in ``case``
622patterns.
623
Terry Jan Reedyf660ce22015-09-24 23:13:49 -0400624Text coloring is done in the background, so uncolorized text is occasionally
625visible. To change the color scheme, use the Configure IDLE dialog
626Highlighting tab. The marking of debugger breakpoint lines in the editor and
627text in popups and dialogs is not user-configurable.
Georg Brandl116aa622007-08-15 14:28:22 +0000628
629
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400630Startup and code execution
631--------------------------
Benjamin Petersonf07d0022009-03-21 17:31:58 +0000632
633Upon startup with the ``-s`` option, IDLE will execute the file referenced by
634the environment variables :envvar:`IDLESTARTUP` or :envvar:`PYTHONSTARTUP`.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200635IDLE first checks for ``IDLESTARTUP``; if ``IDLESTARTUP`` is present the file
636referenced is run. If ``IDLESTARTUP`` is not present, IDLE checks for
Benjamin Petersonf07d0022009-03-21 17:31:58 +0000637``PYTHONSTARTUP``. Files referenced by these environment variables are
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200638convenient places to store functions that are used frequently from the IDLE
Benjamin Petersonf07d0022009-03-21 17:31:58 +0000639shell, or for executing import statements to import common modules.
640
641In addition, ``Tk`` also loads a startup file if it is present. Note that the
642Tk file is loaded unconditionally. This additional file is ``.Idle.py`` and is
643looked for in the user's home directory. Statements in this file will be
Terry Jan Reedy3ab745e2014-12-05 02:43:07 -0500644executed in the Tk namespace, so this file is not useful for importing
645functions to be used from IDLE's Python shell.
Benjamin Petersonf07d0022009-03-21 17:31:58 +0000646
Georg Brandl116aa622007-08-15 14:28:22 +0000647Command line usage
648^^^^^^^^^^^^^^^^^^
649
Martin Panter1050d2d2016-07-26 11:18:21 +0200650.. code-block:: none
Georg Brandl116aa622007-08-15 14:28:22 +0000651
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400652 idle.py [-c command] [-d] [-e] [-h] [-i] [-r file] [-s] [-t title] [-] [arg] ...
Georg Brandl116aa622007-08-15 14:28:22 +0000653
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400654 -c command run command in the shell window
655 -d enable debugger and open shell window
656 -e open editor window
Terry Jan Reedy3399e1e2016-08-30 16:58:01 -0400657 -h print help message with legal combinations and exit
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400658 -i open shell window
659 -r file run file in shell window
660 -s run $IDLESTARTUP or $PYTHONSTARTUP first, in shell window
Georg Brandl116aa622007-08-15 14:28:22 +0000661 -t title set title of shell window
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400662 - run stdin in shell (- must be last option before args)
Georg Brandl116aa622007-08-15 14:28:22 +0000663
664If there are arguments:
665
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400666* If ``-``, ``-c``, or ``r`` is used, all arguments are placed in
667 ``sys.argv[1:...]`` and ``sys.argv[0]`` is set to ``''``, ``'-c'``,
668 or ``'-r'``. No editor window is opened, even if that is the default
669 set in the Options dialog.
Georg Brandl116aa622007-08-15 14:28:22 +0000670
Terry Jan Reedy968e2852015-09-23 03:52:23 -0400671* Otherwise, arguments are files opened for editing and
672 ``sys.argv`` reflects the arguments passed to IDLE itself.
Georg Brandl116aa622007-08-15 14:28:22 +0000673
terryjreedy188aedf2017-06-13 21:32:16 -0400674Startup failure
675^^^^^^^^^^^^^^^
676
677IDLE uses a socket to communicate between the IDLE GUI process and the user
678code execution process. A connection must be established whenever the Shell
679starts or restarts. (The latter is indicated by a divider line that says
680'RESTART'). If the user process fails to connect to the GUI process, it
Terry Jan Reedy1b4a9c72021-03-31 01:19:38 -0400681usually displays a ``Tk`` error box with a 'cannot connect' message
682that directs the user here. It then exits.
683
684One specific connection failure on Unix systems results from
685misconfigured masquerading rules somewhere in a system's network setup.
686When IDLE is started from a terminal, one will see a message starting
687with ``** Invalid host:``.
688The valid value is ``127.0.0.1 (idlelib.rpc.LOCALHOST)``.
689One can diagnose with ``tcpconnect -irv 127.0.0.1 6543`` in one
690terminal window and ``tcplisten <same args>`` in another.
terryjreedy188aedf2017-06-13 21:32:16 -0400691
692A common cause of failure is a user-written file with the same name as a
693standard library module, such as *random.py* and *tkinter.py*. When such a
694file is located in the same directory as a file that is about to be run,
695IDLE cannot import the stdlib file. The current fix is to rename the
696user file.
697
698Though less common than in the past, an antivirus or firewall program may
699stop the connection. If the program cannot be taught to allow the
700connection, then it must be turned off for IDLE to work. It is safe to
701allow this internal connection because no data is visible on external
702ports. A similar problem is a network mis-configuration that blocks
703connections.
704
705Python installation issues occasionally stop IDLE: multiple versions can
706clash, or a single installation might need admin access. If one undo the
707clash, or cannot or does not want to run as admin, it might be easiest to
708completely remove Python and start over.
709
710A zombie pythonw.exe process could be a problem. On Windows, use Task
Jules Lasne (jlasne)ce305d62020-03-06 02:28:14 +0100711Manager to check for one and stop it if there is. Sometimes a restart
712initiated by a program crash or Keyboard Interrupt (control-C) may fail
713to connect. Dismissing the error box or using Restart Shell on the Shell
714menu may fix a temporary problem.
terryjreedy188aedf2017-06-13 21:32:16 -0400715
716When IDLE first starts, it attempts to read user configuration files in
Tal Einatd6c08db2020-01-06 01:51:48 +0200717``~/.idlerc/`` (~ is one's home directory). If there is a problem, an error
terryjreedy188aedf2017-06-13 21:32:16 -0400718message should be displayed. Leaving aside random disk glitches, this can
Jules Lasne (jlasne)ce305d62020-03-06 02:28:14 +0100719be prevented by never editing the files by hand. Instead, use the
720configuration dialog, under Options. Once there is an error in a user
721configuration file, the best solution may be to delete it and start over
722with the settings dialog.
terryjreedy188aedf2017-06-13 21:32:16 -0400723
724If IDLE quits with no message, and it was not started from a console, try
Jules Lasne (jlasne)ce305d62020-03-06 02:28:14 +0100725starting it from a console or terminal (``python -m idlelib``) and see if
726this results in an error message.
terryjreedy188aedf2017-06-13 21:32:16 -0400727
Terry Jan Reedy1b4a9c72021-03-31 01:19:38 -0400728On Unix-based systems with tcl/tk older than ``8.6.11`` (see
729``About IDLE``) certain characters of certain fonts can cause
730a tk failure with a message to the terminal. This can happen either
731if one starts IDLE to edit a file with such a character or later
732when entering such a character. If one cannot upgrade tcl/tk,
733then re-configure IDLE to use a font that works better.
734
Terry Jan Reedy5e790902018-11-05 21:30:32 -0500735Running user code
736^^^^^^^^^^^^^^^^^
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400737
Terry Jan Reedy98758bc2017-09-12 09:05:16 -0400738With rare exceptions, the result of executing Python code with IDLE is
Terry Jan Reedy5e790902018-11-05 21:30:32 -0500739intended to be the same as executing the same code by the default method,
740directly with Python in a text-mode system console or terminal window.
Terry Jan Reedy98758bc2017-09-12 09:05:16 -0400741However, the different interface and operation occasionally affect
Terry Jan Reedy5e790902018-11-05 21:30:32 -0500742visible results. For instance, ``sys.modules`` starts with more entries,
Jelle Zijlstra9825bdf2021-04-12 01:42:53 -0700743and ``threading.active_count()`` returns 2 instead of 1.
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400744
Terry Jan Reedy5e790902018-11-05 21:30:32 -0500745By default, IDLE runs user code in a separate OS process rather than in
746the user interface process that runs the shell and editor. In the execution
747process, it replaces ``sys.stdin``, ``sys.stdout``, and ``sys.stderr``
748with objects that get input from and send output to the Shell window.
749The original values stored in ``sys.__stdin__``, ``sys.__stdout__``, and
750``sys.__stderr__`` are not touched, but may be ``None``.
751
Terry Jan Reedy2827e8a2021-02-23 19:39:51 -0500752Sending print output from one process to a text widget in another is
753slower than printing to a system terminal in the same process.
754This has the most effect when printing multiple arguments, as the string
755for each argument, each separator, the newline are sent separately.
756For development, this is usually not a problem, but if one wants to
757print faster in IDLE, format and join together everything one wants
758displayed together and then print a single string. Both format strings
759and :meth:`str.join` can help combine fields and lines.
760
Terry Jan Reedy5e790902018-11-05 21:30:32 -0500761IDLE's standard stream replacements are not inherited by subprocesses
Terry Jan Reedy4cf7bb82021-02-21 02:44:11 -0500762created in the execution process, whether directly by user code or by
763modules such as multiprocessing. If such subprocess use ``input`` from
764sys.stdin or ``print`` or ``write`` to sys.stdout or sys.stderr,
Terry Jan Reedy5e790902018-11-05 21:30:32 -0500765IDLE should be started in a command line window. The secondary subprocess
766will then be attached to that window for input and output.
767
768If ``sys`` is reset by user code, such as with ``importlib.reload(sys)``,
769IDLE's changes are lost and input from the keyboard and output to the screen
770will not work correctly.
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400771
Terry Jan Reedy4cf7bb82021-02-21 02:44:11 -0500772When Shell has the focus, it controls the keyboard and screen. This is
773normally transparent, but functions that directly access the keyboard
774and screen will not work. These include system-specific functions that
775determine whether a key has been pressed and if so, which.
776
777The IDLE code running in the execution process adds frames to the call stack
778that would not be there otherwise. IDLE wraps ``sys.getrecursionlimit`` and
779``sys.setrecursionlimit`` to reduce the effect of the additional stack
780frames.
781
782When user code raises SystemExit either directly or by calling sys.exit,
783IDLE returns to a Shell prompt instead of exiting.
Terry Jan Reedy6d965b32019-05-19 22:52:22 -0400784
Terry Jan Reedy75d9d592018-11-06 12:37:36 -0500785User output in Shell
786^^^^^^^^^^^^^^^^^^^^
787
788When a program outputs text, the result is determined by the
789corresponding output device. When IDLE executes user code, ``sys.stdout``
790and ``sys.stderr`` are connected to the display area of IDLE's Shell. Some of
791its features are inherited from the underlying Tk Text widget. Others
Terry Jan Reedy76cd0c32018-11-06 23:55:06 -0500792are programmed additions. Where it matters, Shell is designed for development
793rather than production runs.
794
795For instance, Shell never throws away output. A program that sends unlimited
796output to Shell will eventually fill memory, resulting in a memory error.
797In contrast, some system text windows only keep the last n lines of output.
798A Windows console, for instance, keeps a user-settable 1 to 9999 lines,
799with 300 the default.
Terry Jan Reedy75d9d592018-11-06 12:37:36 -0500800
Benjamin Peterson577277f2019-03-25 21:46:35 -0700801A Tk Text widget, and hence IDLE's Shell, displays characters (codepoints) in
802the BMP (Basic Multilingual Plane) subset of Unicode. Which characters are
803displayed with a proper glyph and which with a replacement box depends on the
804operating system and installed fonts. Tab characters cause the following text
805to begin after the next tab stop. (They occur every 8 'characters'). Newline
806characters cause following text to appear on a new line. Other control
807characters are ignored or displayed as a space, box, or something else,
808depending on the operating system and font. (Moving the text cursor through
Terry Jan Reedy55d03512019-04-26 23:22:36 -0400809such output with arrow keys may exhibit some surprising spacing behavior.) ::
Terry Jan Reedy8a03ff22019-02-08 22:51:51 -0500810
Terry Jan Reedy55d03512019-04-26 23:22:36 -0400811 >>> s = 'a\tb\a<\x02><\r>\bc\nd' # Enter 22 chars.
Terry Jan Reedy8a03ff22019-02-08 22:51:51 -0500812 >>> len(s)
813 14
814 >>> s # Display repr(s)
815 'a\tb\x07<\x02><\r>\x08c\nd'
816 >>> print(s, end='') # Display s as is.
817 # Result varies by OS and font. Try it.
818
819The ``repr`` function is used for interactive echo of expression
820values. It returns an altered version of the input string in which
821control codes, some BMP codepoints, and all non-BMP codepoints are
822replaced with escape codes. As demonstrated above, it allows one to
823identify the characters in a string, regardless of how they are displayed.
Terry Jan Reedy75d9d592018-11-06 12:37:36 -0500824
825Normal and error output are generally kept separate (on separate lines)
826from code input and each other. They each get different highlight colors.
827
828For SyntaxError tracebacks, the normal '^' marking where the error was
829detected is replaced by coloring the text with an error highlight.
830When code run from a file causes other exceptions, one may right click
831on a traceback line to jump to the corresponding line in an IDLE editor.
832The file will be opened if necessary.
833
834Shell has a special facility for squeezing output lines down to a
835'Squeezed text' label. This is done automatically
836for output over N lines (N = 50 by default).
837N can be changed in the PyShell section of the General
838page of the Settings dialog. Output with fewer lines can be squeezed by
839right clicking on the output. This can be useful lines long enough to slow
840down scrolling.
841
842Squeezed output is expanded in place by double-clicking the label.
843It can also be sent to the clipboard or a separate view window by
844right-clicking the label.
845
Terry Jan Reedy98758bc2017-09-12 09:05:16 -0400846Developing tkinter applications
847^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
848
849IDLE is intentionally different from standard Python in order to
850facilitate development of tkinter programs. Enter ``import tkinter as tk;
851root = tk.Tk()`` in standard Python and nothing appears. Enter the same
852in IDLE and a tk window appears. In standard Python, one must also enter
853``root.update()`` to see the window. IDLE does the equivalent in the
Terry Jan Reedy8a533ff2019-05-16 01:20:37 -0400854background, about 20 times a second, which is about every 50 milliseconds.
Terry Jan Reedy98758bc2017-09-12 09:05:16 -0400855Next enter ``b = tk.Button(root, text='button'); b.pack()``. Again,
856nothing visibly changes in standard Python until one enters ``root.update()``.
857
858Most tkinter programs run ``root.mainloop()``, which usually does not
859return until the tk app is destroyed. If the program is run with
860``python -i`` or from an IDLE editor, a ``>>>`` shell prompt does not
861appear until ``mainloop()`` returns, at which time there is nothing left
862to interact with.
863
864When running a tkinter program from an IDLE editor, one can comment out
865the mainloop call. One then gets a shell prompt immediately and can
866interact with the live application. One just has to remember to
867re-enable the mainloop call when running in standard Python.
868
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500869Running without a subprocess
870^^^^^^^^^^^^^^^^^^^^^^^^^^^^
871
Terry Jan Reedy0053c472015-09-24 03:09:43 -0400872By default, IDLE executes user code in a separate subprocess via a socket,
Terry Jan Reedy6e10ec52015-09-23 20:00:33 -0400873which uses the internal loopback interface. This connection is not
Miss Islington (bot)6fc1efa2021-07-26 15:34:32 -0700874externally visible and no data is sent to or received from the internet.
Terry Jan Reedy6e10ec52015-09-23 20:00:33 -0400875If firewall software complains anyway, you can ignore it.
876
877If the attempt to make the socket connection fails, Idle will notify you.
878Such failures are sometimes transient, but if persistent, the problem
csabella9dc2b382017-04-29 18:28:36 -0400879may be either a firewall blocking the connection or misconfiguration of
Terry Jan Reedy6e10ec52015-09-23 20:00:33 -0400880a particular system. Until the problem is fixed, one can run Idle with
881the -n command line switch.
882
Terry Jan Reedyf5684942014-12-04 00:54:59 -0500883If IDLE is started with the -n command line switch it will run in a
884single process and will not create the subprocess which runs the RPC
885Python execution server. This can be useful if Python cannot create
886the subprocess or the RPC socket interface on your platform. However,
887in this mode user code is not isolated from IDLE itself. Also, the
888environment is not restarted when Run/Run Module (F5) is selected. If
889your code has been modified, you must reload() the affected modules and
890re-import any specific items (e.g. from foo import baz) if the changes
891are to take effect. For these reasons, it is preferable to run IDLE
892with the default subprocess if at all possible.
893
894.. deprecated:: 3.4
895
Georg Brandl116aa622007-08-15 14:28:22 +0000896
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500897Help and preferences
898--------------------
899
Cheryl Sabella01421be2018-12-20 00:38:54 -0500900.. _help-sources:
901
Terry Jan Reedy18032632018-10-28 16:21:18 -0400902Help sources
903^^^^^^^^^^^^
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200904
Terry Jan Reedy18032632018-10-28 16:21:18 -0400905Help menu entry "IDLE Help" displays a formatted html version of the
906IDLE chapter of the Library Reference. The result, in a read-only
907tkinter text window, is close to what one sees in a web browser.
908Navigate through the text with a mousewheel,
909the scrollbar, or up and down arrow keys held down.
910Or click the TOC (Table of Contents) button and select a section
911header in the opened box.
912
913Help menu entry "Python Docs" opens the extensive sources of help,
Tal Einatd6c08db2020-01-06 01:51:48 +0200914including tutorials, available at ``docs.python.org/x.y``, where 'x.y'
Terry Jan Reedy18032632018-10-28 16:21:18 -0400915is the currently running Python version. If your system
916has an off-line copy of the docs (this may be an installation option),
917that will be opened instead.
918
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200919Selected URLs can be added or removed from the help menu at any time using the
Tal Einatd6c08db2020-01-06 01:51:48 +0200920General tab of the Configure IDLE dialog.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200921
Terry Jan Reedy292cd6e2018-12-20 06:06:29 -0500922.. _preferences:
923
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500924Setting preferences
925^^^^^^^^^^^^^^^^^^^
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200926
927The font preferences, highlighting, keys, and general preferences can be
Terry Jan Reedy292cd6e2018-12-20 06:06:29 -0500928changed via Configure IDLE on the Option menu.
Tal Einatd6c08db2020-01-06 01:51:48 +0200929Non-default user settings are saved in a ``.idlerc`` directory in the user's
Terry Jan Reedy292cd6e2018-12-20 06:06:29 -0500930home directory. Problems caused by bad user configuration files are solved
Tal Einatd6c08db2020-01-06 01:51:48 +0200931by editing or deleting one or more of the files in ``.idlerc``.
Terry Jan Reedy292cd6e2018-12-20 06:06:29 -0500932
Terry Jan Reedyd6101162019-02-23 23:04:53 -0500933On the Font tab, see the text sample for the effect of font face and size
934on multiple characters in multiple languages. Edit the sample to add
935other characters of personal interest. Use the sample to select
936monospaced fonts. If particular characters have problems in Shell or an
937editor, add them to the top of the sample and try changing first size
938and then font.
939
Terry Jan Reedy292cd6e2018-12-20 06:06:29 -0500940On the Highlights and Keys tab, select a built-in or custom color theme
941and key set. To use a newer built-in color theme or key set with older
942IDLEs, save it as a new custom theme or key set and it well be accessible
943to older IDLEs.
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200944
Terry Jan Reedyb65413b2018-11-15 13:15:13 -0500945IDLE on macOS
Terry Jan Reedy50ff02b2018-11-10 23:26:31 -0500946^^^^^^^^^^^^^
947
948Under System Preferences: Dock, one can set "Prefer tabs when opening
949documents" to "Always". This setting is not compatible with the tk/tkinter
950GUI framework used by IDLE, and it breaks a few IDLE features.
951
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200952Extensions
Terry Jan Reedybb37b4c2014-12-04 01:26:04 -0500953^^^^^^^^^^
Andrew Svetlov1bd7f022013-01-14 19:27:36 +0200954
csabella9dc2b382017-04-29 18:28:36 -0400955IDLE contains an extension facility. Preferences for extensions can be
Terry Jan Reedyadb4cd22017-09-12 07:45:15 -0400956changed with the Extensions tab of the preferences dialog. See the
957beginning of config-extensions.def in the idlelib directory for further
958information. The only current default extension is zzdummy, an example
959also used for testing.