<li><ahref="index.html">The Python Standard Library</a>»</li>
<li><ahref="tk.html"accesskey="U">25. Graphical User Interfaces with Tk</a>»</li>
<liclass="nav-item nav-item-1"><ahref="index.html">The Python Standard Library</a>»</li>
<liclass="nav-item nav-item-2"><ahref="tk.html"accesskey="U">25. Graphical User Interfaces with Tk</a>»</li>
</ul>
</div>
<divclass="document">
<divclass="documentwrapper">
<divclass="bodywrapper">
<divclass="body">
<divclass="body"role="main">
<divclass="section"id="idle">
<spanid="id1"></span><h1>25.5. IDLE<aclass="headerlink"href="#idle"title="Permalink to this headline">¶</a></h1>
<pid="index-0">IDLE is Python’s Integrated Development and Learning Environment.</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>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"><codeclass="xref py py-mod docutils literal"><spanclass="pre">tkinter</span></code></a> GUI toolkit</li>
<li>cross-platform: works mostly the same on Windows, Unix, and Mac OS X</li>
<li>Python shell window (interactive interpreter) with colorizing
of code input, output, and error messages</li>
...
...
@@ -224,10 +224,10 @@ Editor window.</dd>
<dt>Run Module</dt>
<dd>Do Check Module (above). If no error, restart the shell to clean the
environment, then execute the module. Output is displayed in the Shell
window. Note that output requires use of <ttclass="docutils literal"><spanclass="pre">print</span></tt> or <ttclass="docutils literal"><spanclass="pre">write</span></tt>.
window. Note that output requires use of <codeclass="docutils literal"><spanclass="pre">print</span></code> or <codeclass="docutils literal"><spanclass="pre">write</span></code>.
When execution is complete, the Shell retains focus and displays a prompt.
At this point, one may interactively explore the result of execution.
This is similar to executing a file with <ttclass="docutils literal"><spanclass="pre">python</span><spanclass="pre">-i</span><spanclass="pre">file</span></tt> at a command
This is similar to executing a file with <codeclass="docutils literal"><spanclass="pre">python</span><spanclass="pre">-i</span><spanclass="pre">file</span></code> at a command
line.</dd>
</dl>
</div>
...
...
@@ -339,47 +339,47 @@ debugger. Breakpoints for a file are saved in the user’s .idlerc director
</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>
<p>In this section, ‘C’ refers to the <codeclass="kbd docutils literal"><spanclass="pre">Control</span></code> key on Windows and Unix and
the <codeclass="kbd docutils literal"><spanclass="pre">Command</span></code> 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><pclass="first"><codeclass="kbd docutils literal"><spanclass="pre">Backspace</span></code> deletes to the left; <codeclass="kbd docutils literal"><spanclass="pre">Del</span></code> 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><pclass="first"><codeclass="kbd docutils literal"><spanclass="pre">C-Backspace</span></code> delete word left; <codeclass="kbd docutils literal"><spanclass="pre">C-Del</span></code> 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><pclass="first">Arrow keys and <codeclass="kbd docutils literal"><spanclass="pre">Page</span><spanclass="pre">Up</span></code>/<codeclass="kbd docutils literal"><spanclass="pre">Page</span><spanclass="pre">Down</span></code> 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><pclass="first"><codeclass="kbd docutils literal"><spanclass="pre">C-LeftArrow</span></code> and <codeclass="kbd docutils literal"><spanclass="pre">C-RightArrow</span></code> 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><pclass="first"><codeclass="kbd docutils literal"><spanclass="pre">Home</span></code>/<codeclass="kbd docutils literal"><spanclass="pre">End</span></code> 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><pclass="first"><codeclass="kbd docutils literal"><spanclass="pre">C-Home</span></code>/<codeclass="kbd docutils literal"><spanclass="pre">C-End</span></code> 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
<li><codeclass="kbd docutils literal"><spanclass="pre">C-a</span></code> beginning of line</li>
<li><codeclass="kbd docutils literal"><spanclass="pre">C-e</span></code> end of line</li>
<li><codeclass="kbd docutils literal"><spanclass="pre">C-k</span></code> kill line (but doesn’t put it in clipboard)</li>
<li><codeclass="kbd docutils literal"><spanclass="pre">C-l</span></code> center window around the insertion point</li>
<li><codeclass="kbd docutils literal"><spanclass="pre">C-b</span></code> 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
<li><codeclass="kbd docutils literal"><spanclass="pre">C-f</span></code> 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
<li><codeclass="kbd docutils literal"><spanclass="pre">C-p</span></code> 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>
<li><codeclass="kbd docutils literal"><spanclass="pre">C-d</span></code> 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)
<p>Standard keybindings (like <codeclass="kbd docutils literal"><spanclass="pre">C-c</span></code> to copy and <codeclass="kbd docutils literal"><spanclass="pre">C-v</span></code> 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
the next line is dedented. In leading indentation, <codeclass="kbd docutils literal"><spanclass="pre">Backspace</span></code> deletes up
to 4 spaces if they are there. <codeclass="kbd docutils literal"><spanclass="pre">Tab</span></code> 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>
...
...
@@ -394,25 +394,25 @@ two seconds) after a ‘.’ or (in a string) an os.sep is typed. If aft
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>
<codeclass="kbd docutils literal"><spanclass="pre">Tab</span></code> 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
<codeclass="kbd docutils literal"><spanclass="pre">C-space</span></code> 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
entry most closely matching those characters. Entering a <codeclass="kbd docutils literal"><spanclass="pre">tab</span></code> 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
Shell. Two <codeclass="kbd docutils literal"><spanclass="pre">tab</span></code> 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>
<codeclass="docutils literal"><spanclass="pre">__all__</span></code> 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
an Editor window which are not via <codeclass="docutils literal"><spanclass="pre">__main__</span></code> and <aclass="reference internal"href="sys.html#sys.modules"title="sys.modules"><codeclass="xref py py-data docutils literal"><spanclass="pre">sys.modules</span></code></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>
...
...
@@ -421,10 +421,10 @@ longer or disable the extension.</p>
</div>
<divclass="section"id="calltips">
<h3>25.5.2.3. Calltips<aclass="headerlink"href="#calltips"title="Permalink to this headline">¶</a></h3>
<p>A calltip is shown when one types <ttclass="kbd docutils literal"><spanclass="pre">(</span></tt> after the name of an <em>acccessible</em>
<p>A calltip is shown when one types <codeclass="kbd docutils literal"><spanclass="pre">(</span></code> after the name of an <em>acccessible</em>
function. A name expression may include dots and subscripts. A calltip
remains until it is clicked, the cursor is moved out of the argument area,
or <ttclass="kbd docutils literal"><spanclass="pre">)</span></tt> is typed. When the cursor is in the argument part of a definition,
or <codeclass="kbd docutils literal"><spanclass="pre">)</span></code> is typed. When the cursor is in the argument part of a definition,
the menu or shortcut display a calltip.</p>
<p>A calltip consists of the function signature and the first line of the
docstring. For builtins without an accessible signature, the calltip
...
...
@@ -433,11 +433,11 @@ details may change.</p>
<p>The set of <em>accessible</em> functions depends on what modules have been imported
into the user process, including those imported by Idle itself,
and what definitions have been run, all since the last restart.</p>
<p>For example, restart the Shell and enter <ttclass="docutils literal"><spanclass="pre">itertools.count(</span></tt>. A calltip
<p>For example, restart the Shell and enter <codeclass="docutils literal"><spanclass="pre">itertools.count(</span></code>. A calltip
appears because Idle imports itertools into the user process for its own use.
(This could change.) Enter <ttclass="docutils literal"><spanclass="pre">turtle.write(</span></tt> and nothing appears. Idle does
(This could change.) Enter <codeclass="docutils literal"><spanclass="pre">turtle.write(</span></code> and nothing appears. Idle does
not import turtle. The menu or shortcut do nothing either. Enter
<ttclass="docutils literal"><spanclass="pre">import</span><spanclass="pre">turtle</span></tt> and then <ttclass="docutils literal"><spanclass="pre">turtle.write(</span></tt> will work.</p>
<codeclass="docutils literal"><spanclass="pre">import</span><spanclass="pre">turtle</span></code> and then <codeclass="docutils literal"><spanclass="pre">turtle.write(</span></code> will work.</p>
<p>In an editor, import statements have no effect until one runs the file. One
might want to run a file after writing the import statements at the top,
or immediately run an existing file before editing.</p>
...
...
@@ -445,17 +445,17 @@ or immediately run an existing file before editing.</p>
<divclass="section"id="python-shell-window">
<h3>25.5.2.4. 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><pclass="first"><codeclass="kbd docutils literal"><spanclass="pre">C-d</span></code> sends end-of-file; closes window if typed at a <codeclass="docutils literal"><spanclass="pre">>>></span></code> prompt</p>
</li>
<li><pclass="first"><ttclass="kbd docutils literal"><spanclass="pre">Alt-/</span></tt> (Expand word) is also useful to reduce typing</p>
<li><pclass="first"><codeclass="kbd docutils literal"><spanclass="pre">Alt-/</span></code> (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>
<li><codeclass="kbd docutils literal"><spanclass="pre">Alt-p</span></code> retrieves previous command matching what you have typed. On
OS X use <codeclass="kbd docutils literal"><spanclass="pre">C-p</span></code>.</li>
<li><codeclass="kbd docutils literal"><spanclass="pre">Alt-n</span></code> retrieves next. On OS X use <codeclass="kbd docutils literal"><spanclass="pre">C-n</span></code>.</li>
<li><codeclass="kbd docutils literal"><spanclass="pre">Return</span></code> while on any previous command retrieves that command</li>
</ul>
</li>
</ul>
...
...
@@ -465,8 +465,8 @@ OS X use <tt class="kbd docutils literal"><span class="pre">C-p</span></tt>.</li
<p>Idle defaults to black on white text, but colors text with special meanings.
For the shell, these are shell output, shell error, user output, and
user error. For Python code, at the shell prompt or in an editor, these are
keywords, builtin class and function names, names following <ttclass="docutils literal"><spanclass="pre">class</span></tt> and
<ttclass="docutils literal"><spanclass="pre">def</span></tt>, strings, and comments. For any text window, these are the cursor (when
keywords, builtin class and function names, names following <codeclass="docutils literal"><spanclass="pre">class</span></code> and
<codeclass="docutils literal"><spanclass="pre">def</span></code>, strings, and comments. For any text window, these are the cursor (when
present), found text (when possible), and selected text.</p>
<p>Text coloring is done in the background, so uncolorized text is occasionally
visible. To change the color scheme, use the Configure IDLE dialog
...
...
@@ -476,15 +476,15 @@ text in popups and dialogs is not user-configurable.</p>
<h2>25.5.3. Startup and code execution<aclass="headerlink"href="#startup-and-code-execution"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
<p>Upon startup with the <codeclass="docutils literal"><spanclass="pre">-s</span></code> option, IDLE will execute the file referenced by
the environment variables <spanclass="target"id="index-5"></span><codeclass="xref std std-envvar docutils literal"><spanclass="pre">IDLESTARTUP</span></code> or <spanclass="target"id="index-6"></span><aclass="reference internal"href="../using/cmdline.html#envvar-PYTHONSTARTUP"><codeclass="xref std std-envvar docutils literal"><spanclass="pre">PYTHONSTARTUP</span></code></a>.
IDLE first checks for <codeclass="docutils literal"><spanclass="pre">IDLESTARTUP</span></code>; if <codeclass="docutils literal"><spanclass="pre">IDLESTARTUP</span></code> is present the file
referenced is run. If <codeclass="docutils literal"><spanclass="pre">IDLESTARTUP</span></code> is not present, IDLE checks for
<codeclass="docutils literal"><spanclass="pre">PYTHONSTARTUP</span></code>. 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
<p>In addition, <codeclass="docutils literal"><spanclass="pre">Tk</span></code> also loads a startup file if it is present. Note that the
Tk file is loaded unconditionally. This additional file is <codeclass="docutils literal"><spanclass="pre">.Idle.py</span></code> 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>
...
...
@@ -505,12 +505,12 @@ functions to be used from IDLE’s Python shell.</p>
</div>
<p>If there are arguments:</p>
<ulclass="simple">
<li>If <ttclass="docutils literal"><spanclass="pre">-</span></tt>, <ttclass="docutils literal"><spanclass="pre">-c</span></tt>, or <ttclass="docutils literal"><spanclass="pre">r</span></tt> is used, all arguments are placed in
<ttclass="docutils literal"><spanclass="pre">sys.argv[1:...]</span></tt> and <ttclass="docutils literal"><spanclass="pre">sys.argv[0]</span></tt> is set to <ttclass="docutils literal"><spanclass="pre">''</span></tt>, <ttclass="docutils literal"><spanclass="pre">'-c'</span></tt>,
or <ttclass="docutils literal"><spanclass="pre">'-r'</span></tt>. No editor window is opened, even if that is the default
<li>If <codeclass="docutils literal"><spanclass="pre">-</span></code>, <codeclass="docutils literal"><spanclass="pre">-c</span></code>, or <codeclass="docutils literal"><spanclass="pre">r</span></code> is used, all arguments are placed in
<codeclass="docutils literal"><spanclass="pre">sys.argv[1:...]</span></code> and <codeclass="docutils literal"><spanclass="pre">sys.argv[0]</span></code> is set to <codeclass="docutils literal"><spanclass="pre">''</span></code>, <codeclass="docutils literal"><spanclass="pre">'-c'</span></code>,
or <codeclass="docutils literal"><spanclass="pre">'-r'</span></code>. No editor window is opened, even if that is the default
set in the Options dialog.</li>
<li>Otherwise, arguments are files opened for editing and
<ttclass="docutils literal"><spanclass="pre">sys.argv</span></tt> reflects the arguments passed to IDLE itself.</li>
<codeclass="docutils literal"><spanclass="pre">sys.argv</span></code> reflects the arguments passed to IDLE itself.</li>