• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1.. _idle:
2
3IDLE
4====
5
6.. moduleauthor:: Guido van Rossum <guido@python.org>
7
8**Source code:** :source:`Lib/idlelib/`
9
10.. index::
11   single: IDLE
12   single: Python Editor
13   single: Integrated Development Environment
14
15--------------
16
17IDLE is Python's Integrated Development and Learning Environment.
18
19IDLE has the following features:
20
21* coded in 100% pure Python, using the :mod:`tkinter` GUI toolkit
22
23* cross-platform: works mostly the same on Windows, Unix, and macOS
24
25* Python shell window (interactive interpreter) with colorizing
26  of code input, output, and error messages
27
28* multi-window text editor with multiple undo, Python colorizing,
29  smart indent, call tips, auto completion, and other features
30
31* search within any window, replace within editor windows, and search
32  through multiple files (grep)
33
34* debugger with persistent breakpoints, stepping, and viewing
35  of global and local namespaces
36
37* configuration, browsers, and other dialogs
38
39Menus
40-----
41
42IDLE has two main window types, the Shell window and the Editor window.  It is
43possible 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.
46
47Output 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
51On macOS, there is one application menu.  It dynamically changes according
52to the window currently selected.  It has an IDLE menu, and some entries
53described below are moved around to conform to Apple guidelines.
54
55File menu (Shell and Editor)
56^^^^^^^^^^^^^^^^^^^^^^^^^^^^
57
58New File
59   Create a new file editing window.
60
61Open...
62   Open an existing file with an Open dialog.
63
64Recent Files
65   Open a list of recent files.  Click one to open it.
66
67Open Module...
68   Open an existing module (searches sys.path).
69
70.. index::
71   single: Class browser
72   single: Path browser
73
74Class Browser
75   Show functions, classes, and methods in the current Editor file in a
76   tree structure.  In the shell, open a module first.
77
78Path Browser
79   Show sys.path directories, modules, functions, classes and methods in a
80   tree structure.
81
82Save
83   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.
87
88Save As...
89   Save the current window with a Save As dialog.  The file saved becomes the
90   new associated file for the window.
91
92Save Copy As...
93   Save the current window to different file without changing the associated
94   file.
95
96Print Window
97   Print the current window to the default printer.
98
99Close
100   Close the current window (ask to save if unsaved).
101
102Exit
103   Close all windows and quit IDLE (ask to save unsaved windows).
104
105Edit menu (Shell and Editor)
106^^^^^^^^^^^^^^^^^^^^^^^^^^^^
107
108Undo
109   Undo the last change to the current window.  A maximum of 1000 changes may
110   be undone.
111
112Redo
113   Redo the last undone change to the current window.
114
115Cut
116   Copy selection into the system-wide clipboard; then delete the selection.
117
118Copy
119   Copy selection into the system-wide clipboard.
120
121Paste
122   Insert contents of the system-wide clipboard into the current window.
123
124The clipboard functions are also available in context menus.
125
126Select All
127   Select the entire contents of the current window.
128
129Find...
130   Open a search dialog with many options
131
132Find Again
133   Repeat the last search, if there is one.
134
135Find Selection
136   Search for the currently selected string, if there is one.
137
138Find in Files...
139   Open a file search dialog.  Put results in a new output window.
140
141Replace...
142   Open a search-and-replace dialog.
143
144Go to Line
145   Move cursor to the line number requested and make that line visible.
146
147Show Completions
148   Open a scrollable list allowing selection of keywords and attributes. See
149   :ref:`Completions <completions>` in the Editing and navigation section below.
150
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.
154
155Show call tip
156   After an unclosed parenthesis for a function, open a small window with
157   function parameter hints.  See :ref:`Calltips <calltips>` in the
158   Editing and navigation section below.
159
160Show surrounding parens
161   Highlight the surrounding parenthesis.
162
163.. _format-menu:
164
165Format menu (Editor window only)
166^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
167
168Indent Region
169   Shift selected lines right by the indent width (default 4 spaces).
170
171Dedent Region
172   Shift selected lines left by the indent width (default 4 spaces).
173
174Comment Out Region
175   Insert ## in front of selected lines.
176
177Uncomment Region
178   Remove leading # or ## from selected lines.
179
180Tabify Region
181   Turn *leading* stretches of spaces into tabs. (Note: We recommend using
182   4 space blocks to indent Python code.)
183
184Untabify Region
185   Turn *all* tabs into the correct number of spaces.
186
187Toggle Tabs
188   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.
193
194Format Paragraph
195   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.
198
199Strip trailing whitespace
200   Remove trailing space and other whitespace characters after the last
201   non-whitespace character of a line by applying str.rstrip to each line,
202   including lines within multiline strings.  Except for Shell windows,
203   remove extra newlines at the end of the file.
204
205.. index::
206   single: Run script
207
208Run menu (Editor window only)
209^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
210
211.. _run-module:
212
213Run Module
214   Do :ref:`Check Module <check-module>`.  If no error, restart the shell to clean the
215   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.
221
222.. _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
229.. _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
243
244Shell menu (Shell window only)
245^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
246
247View Last Restart
248  Scroll the shell window to the last Shell restart.
249
250Restart Shell
251  Restart the shell to clean the environment.
252
253Previous 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
259Interrupt Execution
260  Stop a running program.
261
262Debug menu (Shell window only)
263^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
264
265Go 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.
271
272.. index::
273   single: debugger
274   single: stack viewer
275
276Debugger (toggle)
277   When activated, code entered in the Shell or run from an Editor will run
278   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.
287
288Options menu (Shell and Editor)
289^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
290
291Configure IDLE
292   Open a configuration dialog and change preferences for the following:
293   fonts, indentation, keybindings, text color themes, startup windows and
294   size, additional help sources, and extensions.  On macOS, open the
295   configuration dialog by selecting Preferences in the application
296   menu. For more details, see
297   :ref:`Setting preferences <preferences>` under Help and preferences.
298
299Most configuration options apply to all windows or all future windows.
300The option items below only apply to the active window.
301
302Show/Hide Code Context (Editor Window only)
303   Open a pane at the top of the edit window which shows the block context
304   of the code which has scrolled above the top of the window.  See
305   :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>`).
312
313Zoom/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
316   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.
318   Changing screen settings may invalidate the saved height.  This toggle has
319   no effect when a window is maximized.
320
321Window menu (Shell and Editor)
322^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
323
324Lists the names of all open windows; select one to bring it to the foreground
325(deiconifying it if necessary).
326
327Help menu (Shell and Editor)
328^^^^^^^^^^^^^^^^^^^^^^^^^^^^
329
330About IDLE
331   Display version, copyright, license, credits, and more.
332
333IDLE Help
334   Display this IDLE document, detailing the menu options, basic editing and
335   navigation, and other tips.
336
337Python Docs
338   Access local Python documentation, if installed, or start a web browser
339   and open docs.python.org showing the latest Python documentation.
340
341Turtle Demo
342   Run the turtledemo module with example Python code and turtle drawings.
343
344Additional help sources may be added here with the Configure IDLE dialog under
345the General tab. See the :ref:`Help sources <help-sources>` subsection below
346for more on Help menu choices.
347
348.. index::
349   single: Cut
350   single: Copy
351   single: Paste
352   single: Set Breakpoint
353   single: Clear Breakpoint
354   single: breakpoints
355
356Context Menus
357^^^^^^^^^^^^^^^^^^^^^^^^^^
358
359Open a context menu by right-clicking in a window (Control-click on macOS).
360Context menus have the standard clipboard functions also on the Edit menu.
361
362Cut
363   Copy selection into the system-wide clipboard; then delete the selection.
364
365Copy
366   Copy selection into the system-wide clipboard.
367
368Paste
369   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
373debugger.  Breakpoints for a file are saved in the user's .idlerc directory.
374
375Set Breakpoint
376   Set a breakpoint on the current line.
377
378Clear Breakpoint
379   Clear the breakpoint on that line.
380
381Shell and Output windows also have the following.
382
383Go to file/line
384   Same as in Debug menu.
385
386The Shell window also has an output squeezing facility explained in the *Python
387Shell window* subsection below.
388
389Squeeze
390   If the cursor is over an output line, squeeze all the output between
391   the code above and the prompt below down to a 'Squeezed text' label.
392
393
394.. _editing-and-navigation:
395
396Editing and navigation
397----------------------
398
399Editor windows
400^^^^^^^^^^^^^^
401
402IDLE may open editor windows when it starts, depending on settings
403and how you start IDLE.  Thereafter, use the File menu.  There can be only
404one open editor window for a given file.
405
406The title bar contains the name of the file, the full path, and the version
407of Python and IDLE running the window.  The status bar contains the line
408number ('Ln') and column number ('Col').  Line numbers start with 1;
409column numbers with 0.
410
411IDLE assumes that files with a known .py* extension contain Python code
412and that other files do not.  Run Python code with the Run menu.
413
414Key bindings
415^^^^^^^^^^^^
416
417In this section, 'C' refers to the :kbd:`Control` key on Windows and Unix and
418the :kbd:`Command` key on macOS.
419
420* :kbd:`Backspace` deletes to the left; :kbd:`Del` deletes to the right
421
422* :kbd:`C-Backspace` delete word left; :kbd:`C-Del` delete word to the right
423
424* Arrow keys and :kbd:`Page Up`/:kbd:`Page Down` to move around
425
426* :kbd:`C-LeftArrow` and :kbd:`C-RightArrow` moves by words
427
428* :kbd:`Home`/:kbd:`End` go to begin/end of line
429
430* :kbd:`C-Home`/:kbd:`C-End` go to begin/end of file
431
432* Some useful Emacs bindings are inherited from Tcl/Tk:
433
434   * :kbd:`C-a` beginning of line
435
436   * :kbd:`C-e` end of line
437
438   * :kbd:`C-k` kill line (but doesn't put it in clipboard)
439
440   * :kbd:`C-l` center window around the insertion point
441
442   * :kbd:`C-b` go backward one character without deleting (usually you can
443     also use the cursor key for this)
444
445   * :kbd:`C-f` go forward one character without deleting (usually you can
446     also use the cursor key for this)
447
448   * :kbd:`C-p` go up one line (usually you can also use the cursor key for
449     this)
450
451   * :kbd:`C-d` delete next character
452
453Standard keybindings (like :kbd:`C-c` to copy and :kbd:`C-v` to paste)
454may work.  Keybindings are selected in the Configure IDLE dialog.
455
456Automatic indentation
457^^^^^^^^^^^^^^^^^^^^^
458
459After a block-opening statement, the next line is indented by 4 spaces (in the
460Python Shell window by one tab).  After certain keywords (break, return etc.)
461the next line is dedented.  In leading indentation, :kbd:`Backspace` deletes up
462to 4 spaces if they are there. :kbd:`Tab` inserts spaces (in the Python
463Shell window one tab), number depends on Indent width. Currently, tabs
464are restricted to four spaces due to Tcl/Tk limitations.
465
466See also the indent/dedent region commands on the
467:ref:`Format menu <format-menu>`.
468
469
470.. _completions:
471
472Completions
473^^^^^^^^^^^
474
475Completions are supplied for functions, classes, and attributes of classes,
476both built-in and user-defined. Completions are also provided for
477filenames.
478
479The AutoCompleteWindow (ACW) will open after a predefined delay (default is
480two seconds) after a '.' or (in a string) an os.sep is typed. If after one
481of those characters (plus zero or more other characters) a tab is typed
482the ACW will open immediately if a possible continuation is found.
483
484If there is only one possible completion for the characters entered, a
485:kbd:`Tab` will supply that completion without opening the ACW.
486
487'Show Completions' will force open a completions window, by default the
488:kbd:`C-space` will open a completions window. In an empty
489string, this will contain the files in the current directory. On a
490blank line, it will contain the built-in and user-defined functions and
491classes in the current namespaces, plus any modules imported. If some
492characters have been entered, the ACW will attempt to be more specific.
493
494If a string of characters is typed, the ACW selection will jump to the
495entry most closely matching those characters.  Entering a :kbd:`tab` will
496cause the longest non-ambiguous match to be entered in the Editor window or
497Shell.  Two :kbd:`tab` in a row will supply the current ACW selection, as
498will return or a double click.  Cursor keys, Page Up/Down, mouse selection,
499and the scroll wheel all operate on the ACW.
500
501"Hidden" attributes can be accessed by typing the beginning of hidden
502name after a '.', e.g. '_'. This allows access to modules with
503``__all__`` set, or to class-private attributes.
504
505Completions and the 'Expand Word' facility can save a lot of typing!
506
507Completions are currently limited to those in the namespaces. Names in
508an Editor window which are not via ``__main__`` and :data:`sys.modules` will
509not be found.  Run the module once with your imports to correct this situation.
510Note that IDLE itself places quite a few modules in sys.modules, so
511much can be found by default, e.g. the re module.
512
513If you don't like the ACW popping up unbidden, simply make the delay
514longer or disable the extension.
515
516.. _calltips:
517
518Calltips
519^^^^^^^^
520
521A calltip is shown when one types :kbd:`(` after the name of an *accessible*
522function.  A name expression may include dots and subscripts.  A calltip
523remains until it is clicked, the cursor is moved out of the argument area,
524or :kbd:`)` is typed.  When the cursor is in the argument part of a definition,
525the menu or shortcut display a calltip.
526
527A calltip consists of the function signature and the first line of the
528docstring.  For builtins without an accessible signature, the calltip
529consists of all lines up the fifth line or the first blank line.  These
530details may change.
531
532The set of *accessible* functions depends on what modules have been imported
533into the user process, including those imported by Idle itself,
534and what definitions have been run, all since the last restart.
535
536For example, restart the Shell and enter ``itertools.count(``.  A calltip
537appears because Idle imports itertools into the user process for its own use.
538(This could change.)  Enter ``turtle.write(`` and nothing appears.  Idle does
539not import turtle.  The menu or shortcut do nothing either.  Enter
540``import turtle`` and then ``turtle.write(`` will work.
541
542In an editor, import statements have no effect until one runs the file.  One
543might want to run a file after writing the import statements at the top,
544or immediately run an existing file before editing.
545
546.. _code-context:
547
548Code Context
549^^^^^^^^^^^^
550
551Within an editor window containing Python code, code context can be toggled
552in order to show or hide a pane at the top of the window.  When shown, this
553pane freezes the opening lines for block code, such as those beginning with
554``class``, ``def``, or ``if`` keywords, that would have otherwise scrolled
555out of view.  The size of the pane will be expanded and contracted as needed
556to show the all current levels of context, up to the maximum number of
557lines defined in the Configure IDLE dialog (which defaults to 15).  If there
558are no current context lines and the feature is toggled on, a single blank
559line will display.  Clicking on a line in the context pane will move that
560line to the top of the editor.
561
562The text and background colors for the context pane can be configured under
563the Highlights tab in the Configure IDLE dialog.
564
565Python Shell window
566^^^^^^^^^^^^^^^^^^^
567
568With IDLE's Shell, one enters, edits, and recalls complete statements.
569Most consoles and terminals only work with a single physical line at a time.
570
571When one pastes code into Shell, it is not compiled and possibly executed
572until one hits :kbd:`Return`.  One may edit pasted code first.
573If one pastes more that one statement into Shell, the result will be a
574:exc:`SyntaxError` when multiple statements are compiled as if they were one.
575
576The editing features described in previous subsections work when entering
577code interactively.  IDLE's Shell window also responds to the following keys.
578
579* :kbd:`C-c` interrupts executing command
580
581* :kbd:`C-d` sends end-of-file; closes window if typed at a ``>>>`` prompt
582
583* :kbd:`Alt-/` (Expand word) is also useful to reduce typing
584
585  Command history
586
587  * :kbd:`Alt-p` retrieves previous command matching what you have typed. On
588    macOS use :kbd:`C-p`.
589
590  * :kbd:`Alt-n` retrieves next. On macOS use :kbd:`C-n`.
591
592  * :kbd:`Return` while on any previous command retrieves that command
593
594Text colors
595^^^^^^^^^^^
596
597Idle defaults to black on white text, but colors text with special meanings.
598For the shell, these are shell output, shell error, user output, and
599user error.  For Python code, at the shell prompt or in an editor, these are
600keywords, builtin class and function names, names following ``class`` and
601``def``, strings, and comments. For any text window, these are the cursor (when
602present), found text (when possible), and selected text.
603
604Text coloring is done in the background, so uncolorized text is occasionally
605visible.  To change the color scheme, use the Configure IDLE dialog
606Highlighting tab.  The marking of debugger breakpoint lines in the editor and
607text in popups and dialogs is not user-configurable.
608
609
610Startup and code execution
611--------------------------
612
613Upon startup with the ``-s`` option, IDLE will execute the file referenced by
614the environment variables :envvar:`IDLESTARTUP` or :envvar:`PYTHONSTARTUP`.
615IDLE first checks for ``IDLESTARTUP``; if ``IDLESTARTUP`` is present the file
616referenced is run.  If ``IDLESTARTUP`` is not present, IDLE checks for
617``PYTHONSTARTUP``.  Files referenced by these environment variables are
618convenient places to store functions that are used frequently from the IDLE
619shell, or for executing import statements to import common modules.
620
621In addition, ``Tk`` also loads a startup file if it is present.  Note that the
622Tk file is loaded unconditionally.  This additional file is ``.Idle.py`` and is
623looked for in the user's home directory.  Statements in this file will be
624executed in the Tk namespace, so this file is not useful for importing
625functions to be used from IDLE's Python shell.
626
627Command line usage
628^^^^^^^^^^^^^^^^^^
629
630.. code-block:: none
631
632   idle.py [-c command] [-d] [-e] [-h] [-i] [-r file] [-s] [-t title] [-] [arg] ...
633
634   -c command  run command in the shell window
635   -d          enable debugger and open shell window
636   -e          open editor window
637   -h          print help message with legal combinations and exit
638   -i          open shell window
639   -r file     run file in shell window
640   -s          run $IDLESTARTUP or $PYTHONSTARTUP first, in shell window
641   -t title    set title of shell window
642   -           run stdin in shell (- must be last option before args)
643
644If there are arguments:
645
646* If ``-``, ``-c``, or ``r`` is used, all arguments are placed in
647  ``sys.argv[1:...]`` and ``sys.argv[0]`` is set to ``''``, ``'-c'``,
648  or ``'-r'``.  No editor window is opened, even if that is the default
649  set in the Options dialog.
650
651* Otherwise, arguments are files opened for editing and
652  ``sys.argv`` reflects the arguments passed to IDLE itself.
653
654Startup failure
655^^^^^^^^^^^^^^^
656
657IDLE uses a socket to communicate between the IDLE GUI process and the user
658code execution process.  A connection must be established whenever the Shell
659starts or restarts.  (The latter is indicated by a divider line that says
660'RESTART'). If the user process fails to connect to the GUI process, it
661displays a ``Tk`` error box with a 'cannot connect' message that directs the
662user here.  It then exits.
663
664A common cause of failure is a user-written file with the same name as a
665standard library module, such as *random.py* and *tkinter.py*. When such a
666file is located in the same directory as a file that is about to be run,
667IDLE cannot import the stdlib file.  The current fix is to rename the
668user file.
669
670Though less common than in the past, an antivirus or firewall program may
671stop the connection.  If the program cannot be taught to allow the
672connection, then it must be turned off for IDLE to work.  It is safe to
673allow this internal connection because no data is visible on external
674ports.  A similar problem is a network mis-configuration that blocks
675connections.
676
677Python installation issues occasionally stop IDLE: multiple versions can
678clash, or a single installation might need admin access.  If one undo the
679clash, or cannot or does not want to run as admin, it might be easiest to
680completely remove Python and start over.
681
682A zombie pythonw.exe process could be a problem.  On Windows, use Task
683Manager to detect and stop one.  Sometimes a restart initiated by a program
684crash or Keyboard Interrupt (control-C) may fail to connect.  Dismissing
685the error box or Restart Shell on the Shell menu may fix a temporary problem.
686
687When IDLE first starts, it attempts to read user configuration files in
688~/.idlerc/ (~ is one's home directory).  If there is a problem, an error
689message should be displayed.  Leaving aside random disk glitches, this can
690be prevented by never editing the files by hand, using the configuration
691dialog, under Options, instead Options.  Once it happens, the solution may
692be to delete one or more of the configuration files.
693
694If IDLE quits with no message, and it was not started from a console, try
695starting from a console (``python -m idlelib)`` and see if a message appears.
696
697Running user code
698^^^^^^^^^^^^^^^^^
699
700With rare exceptions, the result of executing Python code with IDLE is
701intended to be the same as executing the same code by the default method,
702directly with Python in a text-mode system console or terminal window.
703However, the different interface and operation occasionally affect
704visible results.  For instance, ``sys.modules`` starts with more entries,
705and ``threading.activeCount()`` returns 2 instead of 1.
706
707By default, IDLE runs user code in a separate OS process rather than in
708the user interface process that runs the shell and editor.  In the execution
709process, it replaces ``sys.stdin``, ``sys.stdout``, and ``sys.stderr``
710with objects that get input from and send output to the Shell window.
711The original values stored in ``sys.__stdin__``, ``sys.__stdout__``, and
712``sys.__stderr__`` are not touched, but may be ``None``.
713
714When Shell has the focus, it controls the keyboard and screen.  This is
715normally transparent, but functions that directly access the keyboard
716and screen will not work.  These include system-specific functions that
717determine whether a key has been pressed and if so, which.
718
719IDLE's standard stream replacements are not inherited by subprocesses
720created in the execution process, whether directly by user code or by modules
721such as multiprocessing.  If such subprocess use ``input`` from sys.stdin
722or ``print`` or ``write`` to sys.stdout or sys.stderr,
723IDLE should be started in a command line window.  The secondary subprocess
724will then be attached to that window for input and output.
725
726The IDLE code running in the execution process adds frames to the call stack
727that would not be there otherwise.  IDLE wraps ``sys.getrecursionlimit`` and
728``sys.setrecursionlimit`` to reduce the effect of the additional stack frames.
729
730If ``sys`` is reset by user code, such as with ``importlib.reload(sys)``,
731IDLE's changes are lost and input from the keyboard and output to the screen
732will not work correctly.
733
734When user code raises SystemExit either directly or by calling sys.exit, IDLE
735returns to a Shell prompt instead of exiting.
736
737User output in Shell
738^^^^^^^^^^^^^^^^^^^^
739
740When a program outputs text, the result is determined by the
741corresponding output device.  When IDLE executes user code, ``sys.stdout``
742and ``sys.stderr`` are connected to the display area of IDLE's Shell.  Some of
743its features are inherited from the underlying Tk Text widget.  Others
744are programmed additions.  Where it matters, Shell is designed for development
745rather than production runs.
746
747For instance, Shell never throws away output.  A program that sends unlimited
748output to Shell will eventually fill memory, resulting in a memory error.
749In contrast, some system text windows only keep the last n lines of output.
750A Windows console, for instance, keeps a user-settable 1 to 9999 lines,
751with 300 the default.
752
753A Tk Text widget, and hence IDLE's Shell, displays characters (codepoints) in
754the BMP (Basic Multilingual Plane) subset of Unicode.  Which characters are
755displayed with a proper glyph and which with a replacement box depends on the
756operating system and installed fonts.  Tab characters cause the following text
757to begin after the next tab stop. (They occur every 8 'characters').  Newline
758characters cause following text to appear on a new line.  Other control
759characters are ignored or displayed as a space, box, or something else,
760depending on the operating system and font.  (Moving the text cursor through
761such output with arrow keys may exhibit some surprising spacing behavior.) ::
762
763   >>> s = 'a\tb\a<\x02><\r>\bc\nd'  # Enter 22 chars.
764   >>> len(s)
765   14
766   >>> s  # Display repr(s)
767   'a\tb\x07<\x02><\r>\x08c\nd'
768   >>> print(s, end='')  # Display s as is.
769   # Result varies by OS and font.  Try it.
770
771The ``repr`` function is used for interactive echo of expression
772values.  It returns an altered version of the input string in which
773control codes, some BMP codepoints, and all non-BMP codepoints are
774replaced with escape codes. As demonstrated above, it allows one to
775identify the characters in a string, regardless of how they are displayed.
776
777Normal and error output are generally kept separate (on separate lines)
778from code input and each other.  They each get different highlight colors.
779
780For SyntaxError tracebacks, the normal '^' marking where the error was
781detected is replaced by coloring the text with an error highlight.
782When code run from a file causes other exceptions, one may right click
783on a traceback line to jump to the corresponding line in an IDLE editor.
784The file will be opened if necessary.
785
786Shell has a special facility for squeezing output lines down to a
787'Squeezed text' label.  This is done automatically
788for output over N lines (N = 50 by default).
789N can be changed in the PyShell section of the General
790page of the Settings dialog.  Output with fewer lines can be squeezed by
791right clicking on the output.  This can be useful lines long enough to slow
792down scrolling.
793
794Squeezed output is expanded in place by double-clicking the label.
795It can also be sent to the clipboard or a separate view window by
796right-clicking the label.
797
798Developing tkinter applications
799^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
800
801IDLE is intentionally different from standard Python in order to
802facilitate development of tkinter programs.  Enter ``import tkinter as tk;
803root = tk.Tk()`` in standard Python and nothing appears.  Enter the same
804in IDLE and a tk window appears.  In standard Python, one must also enter
805``root.update()`` to see the window.  IDLE does the equivalent in the
806background, about 20 times a second, which is about every 50 milliseconds.
807Next enter ``b = tk.Button(root, text='button'); b.pack()``.  Again,
808nothing visibly changes in standard Python until one enters ``root.update()``.
809
810Most tkinter programs run ``root.mainloop()``, which usually does not
811return until the tk app is destroyed.  If the program is run with
812``python -i`` or from an IDLE editor, a ``>>>`` shell prompt does not
813appear until ``mainloop()`` returns, at which time there is nothing left
814to interact with.
815
816When running a tkinter program from an IDLE editor, one can comment out
817the mainloop call.  One then gets a shell prompt immediately and can
818interact with the live application.  One just has to remember to
819re-enable the mainloop call when running in standard Python.
820
821Running without a subprocess
822^^^^^^^^^^^^^^^^^^^^^^^^^^^^
823
824By default, IDLE executes user code in a separate subprocess via a socket,
825which uses the internal loopback interface.  This connection is not
826externally visible and no data is sent to or received from the Internet.
827If firewall software complains anyway, you can ignore it.
828
829If the attempt to make the socket connection fails, Idle will notify you.
830Such failures are sometimes transient, but if persistent, the problem
831may be either a firewall blocking the connection or misconfiguration of
832a particular system.  Until the problem is fixed, one can run Idle with
833the -n command line switch.
834
835If IDLE is started with the -n command line switch it will run in a
836single process and will not create the subprocess which runs the RPC
837Python execution server.  This can be useful if Python cannot create
838the subprocess or the RPC socket interface on your platform.  However,
839in this mode user code is not isolated from IDLE itself.  Also, the
840environment is not restarted when Run/Run Module (F5) is selected.  If
841your code has been modified, you must reload() the affected modules and
842re-import any specific items (e.g. from foo import baz) if the changes
843are to take effect.  For these reasons, it is preferable to run IDLE
844with the default subprocess if at all possible.
845
846.. deprecated:: 3.4
847
848
849Help and preferences
850--------------------
851
852.. _help-sources:
853
854Help sources
855^^^^^^^^^^^^
856
857Help menu entry "IDLE Help" displays a formatted html version of the
858IDLE chapter of the Library Reference.  The result, in a read-only
859tkinter text window, is close to what one sees in a web browser.
860Navigate through the text with a mousewheel,
861the scrollbar, or up and down arrow keys held down.
862Or click the TOC (Table of Contents) button and select a section
863header in the opened box.
864
865Help menu entry "Python Docs" opens the extensive sources of help,
866including tutorials, available at docs.python.org/x.y, where 'x.y'
867is the currently running Python version.  If your system
868has an off-line copy of the docs (this may be an installation option),
869that will be opened instead.
870
871Selected URLs can be added or removed from the help menu at any time using the
872General tab of the Configure IDLE dialog .
873
874.. _preferences:
875
876Setting preferences
877^^^^^^^^^^^^^^^^^^^
878
879The font preferences, highlighting, keys, and general preferences can be
880changed via Configure IDLE on the Option menu.
881Non-default user settings are saved in a .idlerc directory in the user's
882home directory.  Problems caused by bad user configuration files are solved
883by editing or deleting one or more of the files in .idlerc.
884
885On the Font tab, see the text sample for the effect of font face and size
886on multiple characters in multiple languages.  Edit the sample to add
887other characters of personal interest.  Use the sample to select
888monospaced fonts.  If particular characters have problems in Shell or an
889editor, add them to the top of the sample and try changing first size
890and then font.
891
892On the Highlights and Keys tab, select a built-in or custom color theme
893and key set.  To use a newer built-in color theme or key set with older
894IDLEs, save it as a new custom theme or key set and it well be accessible
895to older IDLEs.
896
897IDLE on macOS
898^^^^^^^^^^^^^
899
900Under System Preferences: Dock, one can set "Prefer tabs when opening
901documents" to "Always".  This setting is not compatible with the tk/tkinter
902GUI framework used by IDLE, and it breaks a few IDLE features.
903
904Extensions
905^^^^^^^^^^
906
907IDLE contains an extension facility.  Preferences for extensions can be
908changed with the Extensions tab of the preferences dialog. See the
909beginning of config-extensions.def in the idlelib directory for further
910information.  The only current default extension is zzdummy, an example
911also used for testing.
912