<spanid="id1"></span><h1>25.5. IDLE<aclass="headerlink"href="#idle"title="Permalink to this headline">¶</a></h1>
<pid="index-0">IDLE is the Python IDE built with the <aclass="reference internal"href="tkinter.html#module-tkinter"title="tkinter: Interface to Tcl/Tk for graphical user interfaces"><ttclass="xref py py-mod docutils literal"><spanclass="pre">tkinter</span></tt></a> GUI toolkit.</p>
<p>IDLE has the following features:</p>
<ulclass="simple">
<li>coded in 100% pure Python, using the <aclass="reference internal"href="tkinter.html#module-tkinter"title="tkinter: Interface to Tcl/Tk for graphical user interfaces"><ttclass="xref py py-mod docutils literal"><spanclass="pre">tkinter</span></tt></a> GUI toolkit</li>
<li>cross-platform: works on Windows, Unix, and Mac OS X</li>
<li>multi-window text editor with multiple undo, Python colorizing,
smart indent, call tips, and many other features</li>
<spanid="index-2"></span><h3>25.5.1.4. Run menu (Editor window only)<aclass="headerlink"href="#run-menu-editor-window-only"title="Permalink to this headline">¶</a></h3>
<dlclass="docutils">
<dt>Python Shell</dt>
<dd>Open or wake up the Python Shell window.</dd>
<dt>Check Module</dt>
<dd>Check the syntax of the module currently open in the Editor window. If the
module has not been saved IDLE will either prompt the user to save or
autosave, as selected in the General tab of the Idle Settings dialog. If
there is a syntax error, the approximate location is indicated in the
Editor window.</dd>
<dt>Run Module</dt>
<dd>Do Check Module (above). If no error, restart the shell to clean the
<h3>25.5.1.9. Help menu (Shell and Editor)<aclass="headerlink"href="#help-menu-shell-and-editor"title="Permalink to this headline">¶</a></h3>
<dlclass="docutils">
<dt>About IDLE</dt>
<dd>Display version, copyright, license, credits, and more.</dd>
<dt>IDLE Help</dt>
<dd>Display a help file for IDLE detailing the menu options, basic editing and
navigation, and other tips.</dd>
<dt>Python Docs</dt>
<dd>Access local Python documentation, if installed, or start a web browser
and open docs.python.org showing the latest Python documentation.</dd>
<dt>Turtle Demo</dt>
<dd>Run the turtledemo module with example python code and turtle drawings.</dd>
</dl>
<p>Additional help sources may be added here with the Configure IDLE dialog under
the General tab.</p>
</div>
<divclass="section"id="context-menus">
<spanid="index-4"></span><h3>25.5.1.10. Context Menus<aclass="headerlink"href="#context-menus"title="Permalink to this headline">¶</a></h3>
<p>Open a context menu by right-clicking in a window (Control-click on OS X).
Context menus have the standard clipboard functions also on the Edit menu.</p>
<dlclass="docutils">
<dt>Cut</dt>
<dd>Copy selection into the system-wide clipboard; then delete the selection.</dd>
<dt>Copy</dt>
<dd>Copy selection into the system-wide clipboard.</dd>
<dt>Paste</dt>
<dd>Insert contents of the system-wide clipboard into the current window.</dd>
</dl>
<p>Editor windows also have breakpoint functions. Lines with a breakpoint set are
specially marked. Breakpoints only have an effect when running under the
debugger. Breakpoints for a file are saved in the user’s .idlerc directory.</p>
<dlclass="docutils">
<dt>Set Breakpoint</dt>
<dd>Set a breakpoint on the current line.</dd>
<dt>Clear Breakpoint</dt>
<dd>Clear the breakpoint on that line.</dd>
</dl>
<p>Shell and Output windows have the following.</p>
<dlclass="docutils">
<dt>Go to file/line</dt>
<dd>Same as in Debug menu.</dd>
</dl>
</div>
</div>
<divclass="section"id="editing-and-navigation">
<h2>25.5.2. Editing and navigation<aclass="headerlink"href="#editing-and-navigation"title="Permalink to this headline">¶</a></h2>
<p>In this section, ‘C’ refers to the <ttclass="kbd docutils literal"><spanclass="pre">Control</span></tt> key on Windows and Unix and
the <ttclass="kbd docutils literal"><spanclass="pre">Command</span></tt> key on Mac OSX.</p>
<ul>
<li><pclass="first"><ttclass="kbd docutils literal"><spanclass="pre">Backspace</span></tt> deletes to the left; <ttclass="kbd docutils literal"><spanclass="pre">Del</span></tt> deletes to the right</p>
</li>
<li><pclass="first"><ttclass="kbd docutils literal"><spanclass="pre">C-Backspace</span></tt> delete word left; <ttclass="kbd docutils literal"><spanclass="pre">C-Del</span></tt> delete word to the right</p>
</li>
<li><pclass="first">Arrow keys and <ttclass="kbd docutils literal"><spanclass="pre">Page</span><spanclass="pre">Up</span></tt>/<ttclass="kbd docutils literal"><spanclass="pre">Page</span><spanclass="pre">Down</span></tt> to move around</p>
</li>
<li><pclass="first"><ttclass="kbd docutils literal"><spanclass="pre">C-LeftArrow</span></tt> and <ttclass="kbd docutils literal"><spanclass="pre">C-RightArrow</span></tt> moves by words</p>
</li>
<li><pclass="first"><ttclass="kbd docutils literal"><spanclass="pre">Home</span></tt>/<ttclass="kbd docutils literal"><spanclass="pre">End</span></tt> go to begin/end of line</p>
</li>
<li><pclass="first"><ttclass="kbd docutils literal"><spanclass="pre">C-Home</span></tt>/<ttclass="kbd docutils literal"><spanclass="pre">C-End</span></tt> go to begin/end of file</p>
</li>
<li><pclass="first">Some useful Emacs bindings are inherited from Tcl/Tk:</p>
<blockquote>
<div><ulclass="simple">
<li><ttclass="kbd docutils literal"><spanclass="pre">C-a</span></tt> beginning of line</li>
<li><ttclass="kbd docutils literal"><spanclass="pre">C-e</span></tt> end of line</li>
<li><ttclass="kbd docutils literal"><spanclass="pre">C-k</span></tt> kill line (but doesn’t put it in clipboard)</li>
<li><ttclass="kbd docutils literal"><spanclass="pre">C-l</span></tt> center window around the insertion point</li>
<li><ttclass="kbd docutils literal"><spanclass="pre">C-b</span></tt> go backwards one character without deleting (usually you can
also use the cursor key for this)</li>
<li><ttclass="kbd docutils literal"><spanclass="pre">C-f</span></tt> go forward one character without deleting (usually you can
also use the cursor key for this)</li>
<li><ttclass="kbd docutils literal"><spanclass="pre">C-p</span></tt> go up one line (usually you can also use the cursor key for
this)</li>
<li><ttclass="kbd docutils literal"><spanclass="pre">C-d</span></tt> delete next character</li>
</ul>
</div></blockquote>
</li>
</ul>
<p>Standard keybindings (like <ttclass="kbd docutils literal"><spanclass="pre">C-c</span></tt> to copy and <ttclass="kbd docutils literal"><spanclass="pre">C-v</span></tt> to paste)
may work. Keybindings are selected in the Configure IDLE dialog.</p>
<divclass="section"id="automatic-indentation">
<h3>25.5.2.1. Automatic indentation<aclass="headerlink"href="#automatic-indentation"title="Permalink to this headline">¶</a></h3>
<p>After a block-opening statement, the next line is indented by 4 spaces (in the
Python Shell window by one tab). After certain keywords (break, return etc.)
the next line is dedented. In leading indentation, <ttclass="kbd docutils literal"><spanclass="pre">Backspace</span></tt> deletes up
to 4 spaces if they are there. <ttclass="kbd docutils literal"><spanclass="pre">Tab</span></tt> inserts spaces (in the Python
Shell window one tab), number depends on Indent width. Currently tabs
are restricted to four spaces due to Tcl/Tk limitations.</p>
<p>See also the indent/dedent region commands in the edit menu.</p>
</div>
<divclass="section"id="completions">
<h3>25.5.2.2. Completions<aclass="headerlink"href="#completions"title="Permalink to this headline">¶</a></h3>
<p>Completions are supplied for functions, classes, and attributes of classes,
both built-in and user-defined. Completions are also provided for
filenames.</p>
<p>The AutoCompleteWindow (ACW) will open after a predefined delay (default is
two seconds) after a ‘.’ or (in a string) an os.sep is typed. If after one
of those characters (plus zero or more other characters) a tab is typed
the ACW will open immediately if a possible continuation is found.</p>
<p>If there is only one possible completion for the characters entered, a
<ttclass="kbd docutils literal"><spanclass="pre">Tab</span></tt> will supply that completion without opening the ACW.</p>
<p>‘Show Completions’ will force open a completions window, by default the
<ttclass="kbd docutils literal"><spanclass="pre">C-space</span></tt> will open a completions window. In an empty
string, this will contain the files in the current directory. On a
blank line, it will contain the built-in and user-defined functions and
classes in the current name spaces, plus any modules imported. If some
characters have been entered, the ACW will attempt to be more specific.</p>
<p>If a string of characters is typed, the ACW selection will jump to the
entry most closely matching those characters. Entering a <ttclass="kbd docutils literal"><spanclass="pre">tab</span></tt> will
cause the longest non-ambiguous match to be entered in the Editor window or
Shell. Two <ttclass="kbd docutils literal"><spanclass="pre">tab</span></tt> in a row will supply the current ACW selection, as
will return or a double click. Cursor keys, Page Up/Down, mouse selection,
and the scroll wheel all operate on the ACW.</p>
<p>“Hidden” attributes can be accessed by typing the beginning of hidden
name after a ‘.’, e.g. ‘_’. This allows access to modules with
<ttclass="docutils literal"><spanclass="pre">__all__</span></tt> set, or to class-private attributes.</p>
<p>Completions and the ‘Expand Word’ facility can save a lot of typing!</p>
<p>Completions are currently limited to those in the namespaces. Names in
an Editor window which are not via <ttclass="docutils literal"><spanclass="pre">__main__</span></tt> and <aclass="reference internal"href="sys.html#sys.modules"title="sys.modules"><ttclass="xref py py-data docutils literal"><spanclass="pre">sys.modules</span></tt></a> will
not be found. Run the module once with your imports to correct this situation.
Note that IDLE itself places quite a few modules in sys.modules, so
much can be found by default, e.g. the re module.</p>
<p>If you don’t like the ACW popping up unbidden, simply make the delay
longer or disable the extension. Or another option is the delay could
be set to zero. Another alternative to preventing ACW popups is to
disable the call tips extension.</p>
</div>
<divclass="section"id="python-shell-window">
<h3>25.5.2.3. Python Shell window<aclass="headerlink"href="#python-shell-window"title="Permalink to this headline">¶</a></h3>
<li><pclass="first"><ttclass="kbd docutils literal"><spanclass="pre">C-d</span></tt> sends end-of-file; closes window if typed at a <ttclass="docutils literal"><spanclass="pre">>>></span></tt> prompt</p>
</li>
<li><pclass="first"><ttclass="kbd docutils literal"><spanclass="pre">Alt-/</span></tt> (Expand word) is also useful to reduce typing</p>
<p>Command history</p>
<ulclass="simple">
<li><ttclass="kbd docutils literal"><spanclass="pre">Alt-p</span></tt> retrieves previous command matching what you have typed. On
OS X use <ttclass="kbd docutils literal"><spanclass="pre">C-p</span></tt>.</li>
<li><ttclass="kbd docutils literal"><spanclass="pre">Alt-n</span></tt> retrieves next. On OS X use <ttclass="kbd docutils literal"><spanclass="pre">C-n</span></tt>.</li>
<li><ttclass="kbd docutils literal"><spanclass="pre">Return</span></tt> while on any previous command retrieves that command</li>
</ul>
</li>
</ul>
</div>
</div>
<divclass="section"id="syntax-colors">
<h2>25.5.3. Syntax colors<aclass="headerlink"href="#syntax-colors"title="Permalink to this headline">¶</a></h2>
<p>The coloring is applied in a background “thread,” so you may occasionally see
uncolorized text. To change the color scheme, edit the <ttclass="docutils literal"><spanclass="pre">[Colors]</span></tt> section in
<h2>25.5.4. Startup<aclass="headerlink"href="#startup"title="Permalink to this headline">¶</a></h2>
<p>Upon startup with the <ttclass="docutils literal"><spanclass="pre">-s</span></tt> option, IDLE will execute the file referenced by
the environment variables <spanclass="target"id="index-5"></span><ttclass="xref std std-envvar docutils literal"><spanclass="pre">IDLESTARTUP</span></tt> or <spanclass="target"id="index-6"></span><aclass="reference internal"href="../using/cmdline.html#envvar-PYTHONSTARTUP"><ttclass="xref std std-envvar docutils literal"><spanclass="pre">PYTHONSTARTUP</span></tt></a>.
IDLE first checks for <ttclass="docutils literal"><spanclass="pre">IDLESTARTUP</span></tt>; if <ttclass="docutils literal"><spanclass="pre">IDLESTARTUP</span></tt> is present the file
referenced is run. If <ttclass="docutils literal"><spanclass="pre">IDLESTARTUP</span></tt> is not present, IDLE checks for
<ttclass="docutils literal"><spanclass="pre">PYTHONSTARTUP</span></tt>. Files referenced by these environment variables are
convenient places to store functions that are used frequently from the IDLE
shell, or for executing import statements to import common modules.</p>
<p>In addition, <ttclass="docutils literal"><spanclass="pre">Tk</span></tt> also loads a startup file if it is present. Note that the
Tk file is loaded unconditionally. This additional file is <ttclass="docutils literal"><spanclass="pre">.Idle.py</span></tt> and is
looked for in the user’s home directory. Statements in this file will be
executed in the Tk namespace, so this file is not useful for importing
functions to be used from IDLE’s Python shell.</p>
<divclass="section"id="command-line-usage">
<h3>25.5.4.1. Command line usage<aclass="headerlink"href="#command-line-usage"title="Permalink to this headline">¶</a></h3>
<li>If <ttclass="docutils literal"><spanclass="pre">-e</span></tt> is used, arguments are files opened for editing and
<ttclass="docutils literal"><spanclass="pre">sys.argv</span></tt> reflects the arguments passed to IDLE itself.</li>
<li>Otherwise, if <ttclass="docutils literal"><spanclass="pre">-c</span></tt> is used, all arguments are placed in
<ttclass="docutils literal"><spanclass="pre">sys.argv[1:...]</span></tt>, with <ttclass="docutils literal"><spanclass="pre">sys.argv[0]</span></tt> set to <ttclass="docutils literal"><spanclass="pre">'-c'</span></tt>.</li>
<li>Otherwise, if neither <ttclass="docutils literal"><spanclass="pre">-e</span></tt> nor <ttclass="docutils literal"><spanclass="pre">-c</span></tt> is used, the first
argument is a script which is executed with the remaining arguments in
<ttclass="docutils literal"><spanclass="pre">sys.argv[1:...]</span></tt> and <ttclass="docutils literal"><spanclass="pre">sys.argv[0]</span></tt> set to the script name. If the
script name is ‘-‘, no script is executed but an interactive Python session
is started; the arguments are still available in <ttclass="docutils literal"><spanclass="pre">sys.argv</span></tt>.</li>