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 the cursor to the beginning of the line requested and make that
146   line visible.  A request past the end of the file goes to the end.
147   Clear any selection and update the line and column status.
148
149Show Completions
150   Open a scrollable list allowing selection of existing names. See
151   :ref:`Completions <completions>` in the Editing and navigation section below.
152
153Expand Word
154   Expand a prefix you have typed to match a full word in the same window;
155   repeat to get a different expansion.
156
157Show call tip
158   After an unclosed parenthesis for a function, open a small window with
159   function parameter hints.  See :ref:`Calltips <calltips>` in the
160   Editing and navigation section below.
161
162Show surrounding parens
163   Highlight the surrounding parenthesis.
164
165.. _format-menu:
166
167Format menu (Editor window only)
168^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
169
170Indent Region
171   Shift selected lines right by the indent width (default 4 spaces).
172
173Dedent Region
174   Shift selected lines left by the indent width (default 4 spaces).
175
176Comment Out Region
177   Insert ## in front of selected lines.
178
179Uncomment Region
180   Remove leading # or ## from selected lines.
181
182Tabify Region
183   Turn *leading* stretches of spaces into tabs. (Note: We recommend using
184   4 space blocks to indent Python code.)
185
186Untabify Region
187   Turn *all* tabs into the correct number of spaces.
188
189Toggle Tabs
190   Open a dialog to switch between indenting with spaces and tabs.
191
192New Indent Width
193   Open a dialog to change indent width. The accepted default by the Python
194   community is 4 spaces.
195
196Format Paragraph
197   Reformat the current blank-line-delimited paragraph in comment block or
198   multiline string or selected line in a string.  All lines in the
199   paragraph will be formatted to less than N columns, where N defaults to 72.
200
201Strip trailing whitespace
202   Remove trailing space and other whitespace characters after the last
203   non-whitespace character of a line by applying str.rstrip to each line,
204   including lines within multiline strings.  Except for Shell windows,
205   remove extra newlines at the end of the file.
206
207.. index::
208   single: Run script
209
210Run menu (Editor window only)
211^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
212
213.. _run-module:
214
215Run Module
216   Do :ref:`Check Module <check-module>`.  If no error, restart the shell to clean the
217   environment, then execute the module.  Output is displayed in the Shell
218   window.  Note that output requires use of ``print`` or ``write``.
219   When execution is complete, the Shell retains focus and displays a prompt.
220   At this point, one may interactively explore the result of execution.
221   This is similar to executing a file with ``python -i file`` at a command
222   line.
223
224.. _run-custom:
225
226Run... Customized
227   Same as :ref:`Run Module <run-module>`, but run the module with customized
228   settings.  *Command Line Arguments* extend :data:`sys.argv` as if passed
229   on a command line. The module can be run in the Shell without restarting.
230
231.. _check-module:
232
233Check Module
234   Check the syntax of the module currently open in the Editor window. If the
235   module has not been saved IDLE will either prompt the user to save or
236   autosave, as selected in the General tab of the Idle Settings dialog.  If
237   there is a syntax error, the approximate location is indicated in the
238   Editor window.
239
240.. _python-shell:
241
242Python Shell
243   Open or wake up the Python Shell window.
244
245
246Shell menu (Shell window only)
247^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
248
249View Last Restart
250  Scroll the shell window to the last Shell restart.
251
252Restart Shell
253  Restart the shell to clean the environment and reset display and exception handling.
254
255Previous History
256  Cycle through earlier commands in history which match the current entry.
257
258Next History
259  Cycle through later commands in history which match the current entry.
260
261Interrupt Execution
262  Stop a running program.
263
264Debug menu (Shell window only)
265^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
266
267Go to File/Line
268   Look on the current line. with the cursor, and the line above for a filename
269   and line number.  If found, open the file if not already open, and show the
270   line.  Use this to view source lines referenced in an exception traceback
271   and lines found by Find in Files. Also available in the context menu of
272   the Shell window and Output windows.
273
274.. index::
275   single: debugger
276   single: stack viewer
277
278Debugger (toggle)
279   When activated, code entered in the Shell or run from an Editor will run
280   under the debugger.  In the Editor, breakpoints can be set with the context
281   menu.  This feature is still incomplete and somewhat experimental.
282
283Stack Viewer
284   Show the stack traceback of the last exception in a tree widget, with
285   access to locals and globals.
286
287Auto-open Stack Viewer
288   Toggle automatically opening the stack viewer on an unhandled exception.
289
290Options menu (Shell and Editor)
291^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
292
293Configure IDLE
294   Open a configuration dialog and change preferences for the following:
295   fonts, indentation, keybindings, text color themes, startup windows and
296   size, additional help sources, and extensions.  On macOS, open the
297   configuration dialog by selecting Preferences in the application
298   menu. For more details, see
299   :ref:`Setting preferences <preferences>` under Help and preferences.
300
301Most configuration options apply to all windows or all future windows.
302The option items below only apply to the active window.
303
304Show/Hide Code Context (Editor Window only)
305   Open a pane at the top of the edit window which shows the block context
306   of the code which has scrolled above the top of the window.  See
307   :ref:`Code Context <code-context>` in the Editing and Navigation section
308   below.
309
310Show/Hide Line Numbers (Editor Window only)
311   Open a column to the left of the edit window which shows the number
312   of each line of text.  The default is off, which may be changed in the
313   preferences (see :ref:`Setting preferences <preferences>`).
314
315Zoom/Restore Height
316   Toggles the window between normal size and maximum height. The initial size
317   defaults to 40 lines by 80 chars unless changed on the General tab of the
318   Configure IDLE dialog.  The maximum height for a screen is determined by
319   momentarily maximizing a window the first time one is zoomed on the screen.
320   Changing screen settings may invalidate the saved height.  This toggle has
321   no effect when a window is maximized.
322
323Window menu (Shell and Editor)
324^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
325
326Lists the names of all open windows; select one to bring it to the foreground
327(deiconifying it if necessary).
328
329Help menu (Shell and Editor)
330^^^^^^^^^^^^^^^^^^^^^^^^^^^^
331
332About IDLE
333   Display version, copyright, license, credits, and more.
334
335IDLE Help
336   Display this IDLE document, detailing the menu options, basic editing and
337   navigation, and other tips.
338
339Python Docs
340   Access local Python documentation, if installed, or start a web browser
341   and open docs.python.org showing the latest Python documentation.
342
343Turtle Demo
344   Run the turtledemo module with example Python code and turtle drawings.
345
346Additional help sources may be added here with the Configure IDLE dialog under
347the General tab. See the :ref:`Help sources <help-sources>` subsection below
348for more on Help menu choices.
349
350.. index::
351   single: Cut
352   single: Copy
353   single: Paste
354   single: Set Breakpoint
355   single: Clear Breakpoint
356   single: breakpoints
357
358Context Menus
359^^^^^^^^^^^^^^^^^^^^^^^^^^
360
361Open a context menu by right-clicking in a window (Control-click on macOS).
362Context menus have the standard clipboard functions also on the Edit menu.
363
364Cut
365   Copy selection into the system-wide clipboard; then delete the selection.
366
367Copy
368   Copy selection into the system-wide clipboard.
369
370Paste
371   Insert contents of the system-wide clipboard into the current window.
372
373Editor windows also have breakpoint functions.  Lines with a breakpoint set are
374specially marked.  Breakpoints only have an effect when running under the
375debugger.  Breakpoints for a file are saved in the user's ``.idlerc``
376directory.
377
378Set Breakpoint
379   Set a breakpoint on the current line.
380
381Clear Breakpoint
382   Clear the breakpoint on that line.
383
384Shell and Output windows also have the following.
385
386Go to file/line
387   Same as in Debug menu.
388
389The Shell window also has an output squeezing facility explained in the *Python
390Shell window* subsection below.
391
392Squeeze
393   If the cursor is over an output line, squeeze all the output between
394   the code above and the prompt below down to a 'Squeezed text' label.
395
396
397.. _editing-and-navigation:
398
399Editing and navigation
400----------------------
401
402Editor windows
403^^^^^^^^^^^^^^
404
405IDLE may open editor windows when it starts, depending on settings
406and how you start IDLE.  Thereafter, use the File menu.  There can be only
407one open editor window for a given file.
408
409The title bar contains the name of the file, the full path, and the version
410of Python and IDLE running the window.  The status bar contains the line
411number ('Ln') and column number ('Col').  Line numbers start with 1;
412column numbers with 0.
413
414IDLE assumes that files with a known .py* extension contain Python code
415and that other files do not.  Run Python code with the Run menu.
416
417Key bindings
418^^^^^^^^^^^^
419
420In this section, 'C' refers to the :kbd:`Control` key on Windows and Unix and
421the :kbd:`Command` key on macOS.
422
423* :kbd:`Backspace` deletes to the left; :kbd:`Del` deletes to the right
424
425* :kbd:`C-Backspace` delete word left; :kbd:`C-Del` delete word to the right
426
427* Arrow keys and :kbd:`Page Up`/:kbd:`Page Down` to move around
428
429* :kbd:`C-LeftArrow` and :kbd:`C-RightArrow` moves by words
430
431* :kbd:`Home`/:kbd:`End` go to begin/end of line
432
433* :kbd:`C-Home`/:kbd:`C-End` go to begin/end of file
434
435* Some useful Emacs bindings are inherited from Tcl/Tk:
436
437   * :kbd:`C-a` beginning of line
438
439   * :kbd:`C-e` end of line
440
441   * :kbd:`C-k` kill line (but doesn't put it in clipboard)
442
443   * :kbd:`C-l` center window around the insertion point
444
445   * :kbd:`C-b` go backward one character without deleting (usually you can
446     also use the cursor key for this)
447
448   * :kbd:`C-f` go forward one character without deleting (usually you can
449     also use the cursor key for this)
450
451   * :kbd:`C-p` go up one line (usually you can also use the cursor key for
452     this)
453
454   * :kbd:`C-d` delete next character
455
456Standard keybindings (like :kbd:`C-c` to copy and :kbd:`C-v` to paste)
457may work.  Keybindings are selected in the Configure IDLE dialog.
458
459Automatic indentation
460^^^^^^^^^^^^^^^^^^^^^
461
462After a block-opening statement, the next line is indented by 4 spaces (in the
463Python Shell window by one tab).  After certain keywords (break, return etc.)
464the next line is dedented.  In leading indentation, :kbd:`Backspace` deletes up
465to 4 spaces if they are there. :kbd:`Tab` inserts spaces (in the Python
466Shell window one tab), number depends on Indent width. Currently, tabs
467are restricted to four spaces due to Tcl/Tk limitations.
468
469See also the indent/dedent region commands on the
470:ref:`Format menu <format-menu>`.
471
472.. _completions:
473
474Completions
475^^^^^^^^^^^
476
477Completions are supplied, when requested and available, for module
478names, attributes of classes or functions, or filenames.  Each request
479method displays a completion box with existing names.  (See tab
480completions below for an exception.) For any box, change the name
481being completed and the item highlighted in the box by
482typing and deleting characters; by hitting :kbd:`Up`, :kbd:`Down`,
483:kbd:`PageUp`, :kbd:`PageDown`, :kbd:`Home`, and :kbd:`End` keys;
484and by a single click within the box.  Close the box with :kbd:`Escape`,
485:kbd:`Enter`, and double :kbd:`Tab` keys or clicks outside the box.
486A double click within the box selects and closes.
487
488One way to open a box is to type a key character and wait for a
489predefined interval.  This defaults to 2 seconds; customize it
490in the settings dialog.  (To prevent auto popups, set the delay to a
491large number of milliseconds, such as 100000000.) For imported module
492names or class or function attributes, type '.'.
493For filenames in the root directory, type :data:`os.sep` or
494:data:`os.altsep` immediately after an opening quote.  (On Windows,
495one can specify a drive first.)  Move into subdirectories by typing a
496directory name and a separator.
497
498Instead of waiting, or after a box is closed, open a completion box
499immediately with Show Completions on the Edit menu.  The default hot
500key is :kbd:`C-space`.  If one types a prefix for the desired name
501before opening the box, the first match or near miss is made visible.
502The result is the same as if one enters a prefix
503after the box is displayed.  Show Completions after a quote completes
504filenames in the current directory instead of a root directory.
505
506Hitting :kbd:`Tab` after a prefix usually has the same effect as Show
507Completions.  (With no prefix, it indents.)  However, if there is only
508one match to the prefix, that match is immediately added to the editor
509text without opening a box.
510
511Invoking 'Show Completions', or hitting :kbd:`Tab` after a prefix,
512outside of a string and without a preceding '.' opens a box with
513keywords, builtin names, and available module-level names.
514
515When editing code in an editor (as oppose to Shell), increase the
516available module-level names by running your code
517and not restarting the Shell thereafter.  This is especially useful
518after adding imports at the top of a file.  This also increases
519possible attribute completions.
520
521Completion boxes intially exclude names beginning with '_' or, for
522modules, not included in '__all__'.  The hidden names can be accessed
523by typing '_' after '.', either before or after the box is opened.
524
525.. _calltips:
526
527Calltips
528^^^^^^^^
529
530A calltip is shown automatically when one types :kbd:`(` after the name
531of an *accessible* function.  A function name expression may include
532dots and subscripts.  A calltip remains until it is clicked, the cursor
533is moved out of the argument area, or :kbd:`)` is typed.  Whenever the
534cursor is in the argument part of a definition, select Edit and "Show
535Call Tip" on the menu or enter its shortcut to display a calltip.
536
537The calltip consists of the function's signature and docstring up to
538the latter's first blank line or the fifth non-blank line.  (Some builtin
539functions lack an accessible signature.)  A '/' or '*' in the signature
540indicates that the preceding or following arguments are passed by
541position or name (keyword) only.  Details are subject to change.
542
543In Shell, the accessible functions depends on what modules have been
544imported into the user process, including those imported by Idle itself,
545and which definitions have been run, all since the last restart.
546
547For example, restart the Shell and enter ``itertools.count(``.  A calltip
548appears because Idle imports itertools into the user process for its own
549use.  (This could change.)  Enter ``turtle.write(`` and nothing appears.
550Idle does not itself import turtle.  The menu entry and shortcut also do
551nothing.  Enter ``import turtle``.  Thereafter, ``turtle.write(``
552will display a calltip.
553
554In an editor, import statements have no effect until one runs the file.
555One might want to run a file after writing import statements, after
556adding function definitions, or after opening an existing file.
557
558.. _code-context:
559
560Code Context
561^^^^^^^^^^^^
562
563Within an editor window containing Python code, code context can be toggled
564in order to show or hide a pane at the top of the window.  When shown, this
565pane freezes the opening lines for block code, such as those beginning with
566``class``, ``def``, or ``if`` keywords, that would have otherwise scrolled
567out of view.  The size of the pane will be expanded and contracted as needed
568to show the all current levels of context, up to the maximum number of
569lines defined in the Configure IDLE dialog (which defaults to 15).  If there
570are no current context lines and the feature is toggled on, a single blank
571line will display.  Clicking on a line in the context pane will move that
572line to the top of the editor.
573
574The text and background colors for the context pane can be configured under
575the Highlights tab in the Configure IDLE dialog.
576
577Python Shell window
578^^^^^^^^^^^^^^^^^^^
579
580With IDLE's Shell, one enters, edits, and recalls complete statements.
581Most consoles and terminals only work with a single physical line at a time.
582
583When one pastes code into Shell, it is not compiled and possibly executed
584until one hits :kbd:`Return`.  One may edit pasted code first.
585If one pastes more that one statement into Shell, the result will be a
586:exc:`SyntaxError` when multiple statements are compiled as if they were one.
587
588The editing features described in previous subsections work when entering
589code interactively.  IDLE's Shell window also responds to the following keys.
590
591* :kbd:`C-c` interrupts executing command
592
593* :kbd:`C-d` sends end-of-file; closes window if typed at a ``>>>`` prompt
594
595* :kbd:`Alt-/` (Expand word) is also useful to reduce typing
596
597  Command history
598
599  * :kbd:`Alt-p` retrieves previous command matching what you have typed. On
600    macOS use :kbd:`C-p`.
601
602  * :kbd:`Alt-n` retrieves next. On macOS use :kbd:`C-n`.
603
604  * :kbd:`Return` while on any previous command retrieves that command
605
606Text colors
607^^^^^^^^^^^
608
609Idle defaults to black on white text, but colors text with special meanings.
610For the shell, these are shell output, shell error, user output, and
611user error.  For Python code, at the shell prompt or in an editor, these are
612keywords, builtin class and function names, names following ``class`` and
613``def``, strings, and comments. For any text window, these are the cursor (when
614present), found text (when possible), and selected text.
615
616Text coloring is done in the background, so uncolorized text is occasionally
617visible.  To change the color scheme, use the Configure IDLE dialog
618Highlighting tab.  The marking of debugger breakpoint lines in the editor and
619text in popups and dialogs is not user-configurable.
620
621
622Startup and code execution
623--------------------------
624
625Upon startup with the ``-s`` option, IDLE will execute the file referenced by
626the environment variables :envvar:`IDLESTARTUP` or :envvar:`PYTHONSTARTUP`.
627IDLE first checks for ``IDLESTARTUP``; if ``IDLESTARTUP`` is present the file
628referenced is run.  If ``IDLESTARTUP`` is not present, IDLE checks for
629``PYTHONSTARTUP``.  Files referenced by these environment variables are
630convenient places to store functions that are used frequently from the IDLE
631shell, or for executing import statements to import common modules.
632
633In addition, ``Tk`` also loads a startup file if it is present.  Note that the
634Tk file is loaded unconditionally.  This additional file is ``.Idle.py`` and is
635looked for in the user's home directory.  Statements in this file will be
636executed in the Tk namespace, so this file is not useful for importing
637functions to be used from IDLE's Python shell.
638
639Command line usage
640^^^^^^^^^^^^^^^^^^
641
642.. code-block:: none
643
644   idle.py [-c command] [-d] [-e] [-h] [-i] [-r file] [-s] [-t title] [-] [arg] ...
645
646   -c command  run command in the shell window
647   -d          enable debugger and open shell window
648   -e          open editor window
649   -h          print help message with legal combinations and exit
650   -i          open shell window
651   -r file     run file in shell window
652   -s          run $IDLESTARTUP or $PYTHONSTARTUP first, in shell window
653   -t title    set title of shell window
654   -           run stdin in shell (- must be last option before args)
655
656If there are arguments:
657
658* If ``-``, ``-c``, or ``r`` is used, all arguments are placed in
659  ``sys.argv[1:...]`` and ``sys.argv[0]`` is set to ``''``, ``'-c'``,
660  or ``'-r'``.  No editor window is opened, even if that is the default
661  set in the Options dialog.
662
663* Otherwise, arguments are files opened for editing and
664  ``sys.argv`` reflects the arguments passed to IDLE itself.
665
666Startup failure
667^^^^^^^^^^^^^^^
668
669IDLE uses a socket to communicate between the IDLE GUI process and the user
670code execution process.  A connection must be established whenever the Shell
671starts or restarts.  (The latter is indicated by a divider line that says
672'RESTART'). If the user process fails to connect to the GUI process, it
673usually displays a ``Tk`` error box with a 'cannot connect' message
674that directs the user here.  It then exits.
675
676One specific connection failure on Unix systems results from
677misconfigured masquerading rules somewhere in a system's network setup.
678When IDLE is started from a terminal, one will see a message starting
679with ``** Invalid host:``.
680The valid value is ``127.0.0.1 (idlelib.rpc.LOCALHOST)``.
681One can diagnose with ``tcpconnect -irv 127.0.0.1 6543`` in one
682terminal window and ``tcplisten <same args>`` in another.
683
684A common cause of failure is a user-written file with the same name as a
685standard library module, such as *random.py* and *tkinter.py*. When such a
686file is located in the same directory as a file that is about to be run,
687IDLE cannot import the stdlib file.  The current fix is to rename the
688user file.
689
690Though less common than in the past, an antivirus or firewall program may
691stop the connection.  If the program cannot be taught to allow the
692connection, then it must be turned off for IDLE to work.  It is safe to
693allow this internal connection because no data is visible on external
694ports.  A similar problem is a network mis-configuration that blocks
695connections.
696
697Python installation issues occasionally stop IDLE: multiple versions can
698clash, or a single installation might need admin access.  If one undo the
699clash, or cannot or does not want to run as admin, it might be easiest to
700completely remove Python and start over.
701
702A zombie pythonw.exe process could be a problem.  On Windows, use Task
703Manager to check for one and stop it if there is.  Sometimes a restart
704initiated by a program crash or Keyboard Interrupt (control-C) may fail
705to connect.  Dismissing the error box or using Restart Shell on the Shell
706menu may fix a temporary problem.
707
708When IDLE first starts, it attempts to read user configuration files in
709``~/.idlerc/`` (~ is one's home directory).  If there is a problem, an error
710message should be displayed.  Leaving aside random disk glitches, this can
711be prevented by never editing the files by hand.  Instead, use the
712configuration dialog, under Options.  Once there is an error in a user
713configuration file, the best solution may be to delete it and start over
714with the settings dialog.
715
716If IDLE quits with no message, and it was not started from a console, try
717starting it from a console or terminal (``python -m idlelib``) and see if
718this results in an error message.
719
720On Unix-based systems with tcl/tk older than ``8.6.11`` (see
721``About IDLE``) certain characters of certain fonts can cause
722a tk failure with a message to the terminal.  This can happen either
723if one starts IDLE to edit a file with such a character or later
724when entering such a character.  If one cannot upgrade tcl/tk,
725then re-configure IDLE to use a font that works better.
726
727Running user code
728^^^^^^^^^^^^^^^^^
729
730With rare exceptions, the result of executing Python code with IDLE is
731intended to be the same as executing the same code by the default method,
732directly with Python in a text-mode system console or terminal window.
733However, the different interface and operation occasionally affect
734visible results.  For instance, ``sys.modules`` starts with more entries,
735and ``threading.active_count()`` returns 2 instead of 1.
736
737By default, IDLE runs user code in a separate OS process rather than in
738the user interface process that runs the shell and editor.  In the execution
739process, it replaces ``sys.stdin``, ``sys.stdout``, and ``sys.stderr``
740with objects that get input from and send output to the Shell window.
741The original values stored in ``sys.__stdin__``, ``sys.__stdout__``, and
742``sys.__stderr__`` are not touched, but may be ``None``.
743
744Sending print output from one process to a text widget in another is
745slower than printing to a system terminal in the same process.
746This has the most effect when printing multiple arguments, as the string
747for each argument, each separator, the newline are sent separately.
748For development, this is usually not a problem, but if one wants to
749print faster in IDLE, format and join together everything one wants
750displayed together and then print a single string.  Both format strings
751and :meth:`str.join` can help combine fields and lines.
752
753IDLE's standard stream replacements are not inherited by subprocesses
754created in the execution process, whether directly by user code or by
755modules such as multiprocessing.  If such subprocess use ``input`` from
756sys.stdin or ``print`` or ``write`` to sys.stdout or sys.stderr,
757IDLE should be started in a command line window.  The secondary subprocess
758will then be attached to that window for input and output.
759
760If ``sys`` is reset by user code, such as with ``importlib.reload(sys)``,
761IDLE's changes are lost and input from the keyboard and output to the screen
762will not work correctly.
763
764When Shell has the focus, it controls the keyboard and screen.  This is
765normally transparent, but functions that directly access the keyboard
766and screen will not work.  These include system-specific functions that
767determine whether a key has been pressed and if so, which.
768
769The IDLE code running in the execution process adds frames to the call stack
770that would not be there otherwise.  IDLE wraps ``sys.getrecursionlimit`` and
771``sys.setrecursionlimit`` to reduce the effect of the additional stack
772frames.
773
774When user code raises SystemExit either directly or by calling sys.exit,
775IDLE returns to a Shell prompt instead of exiting.
776
777User output in Shell
778^^^^^^^^^^^^^^^^^^^^
779
780When a program outputs text, the result is determined by the
781corresponding output device.  When IDLE executes user code, ``sys.stdout``
782and ``sys.stderr`` are connected to the display area of IDLE's Shell.  Some of
783its features are inherited from the underlying Tk Text widget.  Others
784are programmed additions.  Where it matters, Shell is designed for development
785rather than production runs.
786
787For instance, Shell never throws away output.  A program that sends unlimited
788output to Shell will eventually fill memory, resulting in a memory error.
789In contrast, some system text windows only keep the last n lines of output.
790A Windows console, for instance, keeps a user-settable 1 to 9999 lines,
791with 300 the default.
792
793A Tk Text widget, and hence IDLE's Shell, displays characters (codepoints) in
794the BMP (Basic Multilingual Plane) subset of Unicode.  Which characters are
795displayed with a proper glyph and which with a replacement box depends on the
796operating system and installed fonts.  Tab characters cause the following text
797to begin after the next tab stop. (They occur every 8 'characters').  Newline
798characters cause following text to appear on a new line.  Other control
799characters are ignored or displayed as a space, box, or something else,
800depending on the operating system and font.  (Moving the text cursor through
801such output with arrow keys may exhibit some surprising spacing behavior.) ::
802
803   >>> s = 'a\tb\a<\x02><\r>\bc\nd'  # Enter 22 chars.
804   >>> len(s)
805   14
806   >>> s  # Display repr(s)
807   'a\tb\x07<\x02><\r>\x08c\nd'
808   >>> print(s, end='')  # Display s as is.
809   # Result varies by OS and font.  Try it.
810
811The ``repr`` function is used for interactive echo of expression
812values.  It returns an altered version of the input string in which
813control codes, some BMP codepoints, and all non-BMP codepoints are
814replaced with escape codes. As demonstrated above, it allows one to
815identify the characters in a string, regardless of how they are displayed.
816
817Normal and error output are generally kept separate (on separate lines)
818from code input and each other.  They each get different highlight colors.
819
820For SyntaxError tracebacks, the normal '^' marking where the error was
821detected is replaced by coloring the text with an error highlight.
822When code run from a file causes other exceptions, one may right click
823on a traceback line to jump to the corresponding line in an IDLE editor.
824The file will be opened if necessary.
825
826Shell has a special facility for squeezing output lines down to a
827'Squeezed text' label.  This is done automatically
828for output over N lines (N = 50 by default).
829N can be changed in the PyShell section of the General
830page of the Settings dialog.  Output with fewer lines can be squeezed by
831right clicking on the output.  This can be useful lines long enough to slow
832down scrolling.
833
834Squeezed output is expanded in place by double-clicking the label.
835It can also be sent to the clipboard or a separate view window by
836right-clicking the label.
837
838Developing tkinter applications
839^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
840
841IDLE is intentionally different from standard Python in order to
842facilitate development of tkinter programs.  Enter ``import tkinter as tk;
843root = tk.Tk()`` in standard Python and nothing appears.  Enter the same
844in IDLE and a tk window appears.  In standard Python, one must also enter
845``root.update()`` to see the window.  IDLE does the equivalent in the
846background, about 20 times a second, which is about every 50 milliseconds.
847Next enter ``b = tk.Button(root, text='button'); b.pack()``.  Again,
848nothing visibly changes in standard Python until one enters ``root.update()``.
849
850Most tkinter programs run ``root.mainloop()``, which usually does not
851return until the tk app is destroyed.  If the program is run with
852``python -i`` or from an IDLE editor, a ``>>>`` shell prompt does not
853appear until ``mainloop()`` returns, at which time there is nothing left
854to interact with.
855
856When running a tkinter program from an IDLE editor, one can comment out
857the mainloop call.  One then gets a shell prompt immediately and can
858interact with the live application.  One just has to remember to
859re-enable the mainloop call when running in standard Python.
860
861Running without a subprocess
862^^^^^^^^^^^^^^^^^^^^^^^^^^^^
863
864By default, IDLE executes user code in a separate subprocess via a socket,
865which uses the internal loopback interface.  This connection is not
866externally visible and no data is sent to or received from the Internet.
867If firewall software complains anyway, you can ignore it.
868
869If the attempt to make the socket connection fails, Idle will notify you.
870Such failures are sometimes transient, but if persistent, the problem
871may be either a firewall blocking the connection or misconfiguration of
872a particular system.  Until the problem is fixed, one can run Idle with
873the -n command line switch.
874
875If IDLE is started with the -n command line switch it will run in a
876single process and will not create the subprocess which runs the RPC
877Python execution server.  This can be useful if Python cannot create
878the subprocess or the RPC socket interface on your platform.  However,
879in this mode user code is not isolated from IDLE itself.  Also, the
880environment is not restarted when Run/Run Module (F5) is selected.  If
881your code has been modified, you must reload() the affected modules and
882re-import any specific items (e.g. from foo import baz) if the changes
883are to take effect.  For these reasons, it is preferable to run IDLE
884with the default subprocess if at all possible.
885
886.. deprecated:: 3.4
887
888
889Help and preferences
890--------------------
891
892.. _help-sources:
893
894Help sources
895^^^^^^^^^^^^
896
897Help menu entry "IDLE Help" displays a formatted html version of the
898IDLE chapter of the Library Reference.  The result, in a read-only
899tkinter text window, is close to what one sees in a web browser.
900Navigate through the text with a mousewheel,
901the scrollbar, or up and down arrow keys held down.
902Or click the TOC (Table of Contents) button and select a section
903header in the opened box.
904
905Help menu entry "Python Docs" opens the extensive sources of help,
906including tutorials, available at ``docs.python.org/x.y``, where 'x.y'
907is the currently running Python version.  If your system
908has an off-line copy of the docs (this may be an installation option),
909that will be opened instead.
910
911Selected URLs can be added or removed from the help menu at any time using the
912General tab of the Configure IDLE dialog.
913
914.. _preferences:
915
916Setting preferences
917^^^^^^^^^^^^^^^^^^^
918
919The font preferences, highlighting, keys, and general preferences can be
920changed via Configure IDLE on the Option menu.
921Non-default user settings are saved in a ``.idlerc`` directory in the user's
922home directory.  Problems caused by bad user configuration files are solved
923by editing or deleting one or more of the files in ``.idlerc``.
924
925On the Font tab, see the text sample for the effect of font face and size
926on multiple characters in multiple languages.  Edit the sample to add
927other characters of personal interest.  Use the sample to select
928monospaced fonts.  If particular characters have problems in Shell or an
929editor, add them to the top of the sample and try changing first size
930and then font.
931
932On the Highlights and Keys tab, select a built-in or custom color theme
933and key set.  To use a newer built-in color theme or key set with older
934IDLEs, save it as a new custom theme or key set and it well be accessible
935to older IDLEs.
936
937IDLE on macOS
938^^^^^^^^^^^^^
939
940Under System Preferences: Dock, one can set "Prefer tabs when opening
941documents" to "Always".  This setting is not compatible with the tk/tkinter
942GUI framework used by IDLE, and it breaks a few IDLE features.
943
944Extensions
945^^^^^^^^^^
946
947IDLE contains an extension facility.  Preferences for extensions can be
948changed with the Extensions tab of the preferences dialog. See the
949beginning of config-extensions.def in the idlelib directory for further
950information.  The only current default extension is zzdummy, an example
951also used for testing.
952