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