codekingpro/portable-devtools
114k
1<section id="idle">2<span id="idle-python-editor-and-shell"></span><h1>IDLE — Python editor and shell<a class="headerlink" href="#idle" title="Link to this heading">¶</a></h1>3<p><strong>Source code:</strong> <a class="extlink-source reference external" href="https://github.com/python/cpython/tree/main/Lib/idlelib/">Lib/idlelib/</a></p>4<span class="target" id="index-0"></span><hr class="docutils" />5<p>IDLE is Python’s Integrated Development and Learning Environment.</p>6<p>IDLE has the following features:</p>7<ul class="simple">8<li><p>cross-platform: works mostly the same on Windows, Unix, and macOS</p></li>9<li><p>Python shell window (interactive interpreter) with colorizing10of code input, output, and error messages</p></li>11<li><p>multi-window text editor with multiple undo, Python colorizing,12smart indent, call tips, auto completion, and other features</p></li>13<li><p>search within any window, replace within editor windows, and search14through multiple files (grep)</p></li>15<li><p>debugger with persistent breakpoints, stepping, and viewing16of global and local namespaces</p></li>17<li><p>configuration, browsers, and other dialogs</p></li>18</ul>19<p>The IDLE application is implemented in the <a class="reference internal" href="#module-idlelib" title="idlelib: Implementation package for the IDLE shell/editor."><code class="xref py py-mod docutils literal notranslate"><span class="pre">idlelib</span></code></a> package.</p>20<p>This is an <a class="reference internal" href="../glossary.html#term-optional-module"><span class="xref std std-term">optional module</span></a>.21If it is missing from your copy of CPython,22look for documentation from your distributor (that is,23whoever provided Python to you).24If you are the distributor, see <a class="reference internal" href="../using/configure.html#optional-module-requirements"><span class="std std-ref">Requirements for optional modules</span></a>.</p>25<section id="menus">26<h2>Menus<a class="headerlink" href="#menus" title="Link to this heading">¶</a></h2>27<p>IDLE has two main window types, the Shell window and the Editor window. It is28possible to have multiple editor windows simultaneously. On Windows and29Linux, each has its own top menu. Each menu documented below indicates30which window type it is associated with.</p>31<p>Output windows, such as used for Edit => Find in Files, are a subtype of editor32window. They currently have the same top menu but a different33default title and context menu.</p>34<p>On macOS, there is one application menu. It dynamically changes according35to the window currently selected. It has an IDLE menu, and some entries36described below are moved around to conform to Apple guidelines.</p>37<section id="file-menu-shell-and-editor">38<h3>File menu (Shell and Editor)<a class="headerlink" href="#file-menu-shell-and-editor" title="Link to this heading">¶</a></h3>39<dl class="simple">40<dt>New File</dt><dd><p>Create a new file editing window.</p>41</dd>42<dt>Open…</dt><dd><p>Open an existing file with an Open dialog.</p>43</dd>44<dt>Open Module…</dt><dd><p>Open an existing module (searches sys.path).</p>45</dd>46<dt>Recent Files</dt><dd><p>Open a list of recent files. Click one to open it.</p>47</dd>48</dl>49<dl class="simple" id="index-1">50<dt>Module Browser</dt><dd><p>Show functions, classes, and methods in the current Editor file in a51tree structure. In the shell, open a module first.</p>52</dd>53<dt>Path Browser</dt><dd><p>Show sys.path directories, modules, functions, classes and methods in a54tree structure.</p>55</dd>56<dt>Save</dt><dd><p>Save the current window to the associated file, if there is one. Windows57that have been changed since being opened or last saved have a * before58and after the window title. If there is no associated file,59do Save As instead.</p>60</dd>61<dt>Save As…</dt><dd><p>Save the current window with a Save As dialog. The file saved becomes the62new associated file for the window. (If your file manager is set to hide63extensions, the current extension will be omitted in the file name box.64If the new filename has no ‘.’, ‘.py’ and ‘.txt’ will be added for Python65and text files, except that on macOS Aqua,’.py’ is added for all files.)</p>66</dd>67<dt>Save Copy As…</dt><dd><p>Save the current window to different file without changing the associated68file. (See Save As note above about filename extensions.)</p>69</dd>70<dt>Print Window</dt><dd><p>Print the current window to the default printer.</p>71</dd>72<dt>Close Window</dt><dd><p>Close the current window (if an unsaved editor, ask to save; if an unsaved73Shell, ask to quit execution). Calling <code class="docutils literal notranslate"><span class="pre">exit()</span></code> or <code class="docutils literal notranslate"><span class="pre">close()</span></code> in the Shell74window also closes Shell. If this is the only window, also exit IDLE.</p>75</dd>76<dt>Exit IDLE</dt><dd><p>Close all windows and quit IDLE (ask to save unsaved edit windows).</p>77</dd>78</dl>79</section>80<section id="edit-menu-shell-and-editor">81<h3>Edit menu (Shell and Editor)<a class="headerlink" href="#edit-menu-shell-and-editor" title="Link to this heading">¶</a></h3>82<dl class="simple">83<dt>Undo</dt><dd><p>Undo the last change to the current window. A maximum of 1000 changes may84be undone.</p>85</dd>86<dt>Redo</dt><dd><p>Redo the last undone change to the current window.</p>87</dd>88<dt>Select All</dt><dd><p>Select the entire contents of the current window.</p>89</dd>90<dt>Cut</dt><dd><p>Copy selection into the system-wide clipboard; then delete the selection.</p>91</dd>92<dt>Copy</dt><dd><p>Copy selection into the system-wide clipboard.</p>93</dd>94<dt>Paste</dt><dd><p>Insert contents of the system-wide clipboard into the current window.</p>95</dd>96</dl>97<p>The clipboard functions are also available in context menus.</p>98<dl class="simple">99<dt>Find…</dt><dd><p>Open a search dialog with many options</p>100</dd>101<dt>Find Again</dt><dd><p>Repeat the last search, if there is one.</p>102</dd>103<dt>Find Selection</dt><dd><p>Search for the currently selected string, if there is one.</p>104</dd>105<dt>Find in Files…</dt><dd><p>Open a file search dialog. Put results in a new output window.</p>106</dd>107<dt>Replace…</dt><dd><p>Open a search-and-replace dialog.</p>108</dd>109<dt>Go to Line</dt><dd><p>Move the cursor to the beginning of the line requested and make that110line visible. A request past the end of the file goes to the end.111Clear any selection and update the line and column status.</p>112</dd>113<dt>Show Completions</dt><dd><p>Open a scrollable list allowing selection of existing names. See114<a class="reference internal" href="#completions"><span class="std std-ref">Completions</span></a> in the Editing and Navigation section below.</p>115</dd>116<dt>Expand Word</dt><dd><p>Expand a prefix you have typed to match a full word in the same window;117repeat to get a different expansion.</p>118</dd>119<dt>Show Call Tip</dt><dd><p>After an unclosed parenthesis for a function, open a small window with120function parameter hints. See <a class="reference internal" href="#calltips"><span class="std std-ref">Calltips</span></a> in the121Editing and Navigation section below.</p>122</dd>123<dt>Show Surrounding Parens</dt><dd><p>Highlight the surrounding parenthesis.</p>124</dd>125</dl>126</section>127<section id="format-menu-editor-window-only">128<span id="format-menu"></span><h3>Format menu (Editor window only)<a class="headerlink" href="#format-menu-editor-window-only" title="Link to this heading">¶</a></h3>129<dl class="simple">130<dt>Format Paragraph</dt><dd><p>Rewrap the text block containing the text insert cursor.131Avoid code lines. See <a class="reference internal" href="#format-block"><span class="std std-ref">Format block</span></a> in the132Editing and Navigation section below.</p>133</dd>134<dt>Indent Region</dt><dd><p>Shift selected lines right by the indent width (default 4 spaces).</p>135</dd>136<dt>Dedent Region</dt><dd><p>Shift selected lines left by the indent width (default 4 spaces).</p>137</dd>138<dt>Comment Out Region</dt><dd><p>Insert ## in front of selected lines.</p>139</dd>140<dt>Uncomment Region</dt><dd><p>Remove leading # or ## from selected lines.</p>141</dd>142<dt>Tabify Region</dt><dd><p>Turn <em>leading</em> stretches of spaces into tabs. (Note: We recommend using1434 space blocks to indent Python code.)</p>144</dd>145<dt>Untabify Region</dt><dd><p>Turn <em>all</em> tabs into the correct number of spaces.</p>146</dd>147<dt>Toggle Tabs</dt><dd><p>Open a dialog to switch between indenting with spaces and tabs.</p>148</dd>149<dt>New Indent Width</dt><dd><p>Open a dialog to change indent width. The accepted default by the Python150community is 4 spaces.</p>151</dd>152<dt>Strip Trailing Whitespace</dt><dd><p>Remove trailing space and other whitespace characters after the last153non-whitespace character of a line by applying <a class="reference internal" href="stdtypes.html#str.rstrip" title="str.rstrip"><code class="xref py py-meth docutils literal notranslate"><span class="pre">str.rstrip()</span></code></a> to each line,154including lines within multiline strings. Except for Shell windows,155remove extra newlines at the end of the file.</p>156</dd>157</dl>158</section>159<section id="run-menu-editor-window-only">160<span id="index-2"></span><h3>Run menu (Editor window only)<a class="headerlink" href="#run-menu-editor-window-only" title="Link to this heading">¶</a></h3>161<dl class="simple" id="run-module">162<dt>Run Module</dt><dd><p>Do <a class="reference internal" href="#check-module"><span class="std std-ref">Check Module</span></a>. If no error, restart the shell to clean the163environment, then execute the module. Output is displayed in the Shell164window. Note that output requires use of <code class="docutils literal notranslate"><span class="pre">print</span></code> or <code class="docutils literal notranslate"><span class="pre">write</span></code>.165When execution is complete, the Shell retains focus and displays a prompt.166At this point, one may interactively explore the result of execution.167This is similar to executing a file with <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-i</span> <span class="pre">file</span></code> at a command168line.</p>169</dd>170</dl>171<dl class="simple" id="run-custom">172<dt>Run… Customized</dt><dd><p>Same as <a class="reference internal" href="#run-module"><span class="std std-ref">Run Module</span></a>, but run the module with customized173settings. <em>Command Line Arguments</em> extend <a class="reference internal" href="sys.html#sys.argv" title="sys.argv"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.argv</span></code></a> as if passed174on a command line. The module can be run in the Shell without restarting.</p>175</dd>176</dl>177<dl class="simple" id="check-module">178<dt>Check Module</dt><dd><p>Check the syntax of the module currently open in the Editor window. If the179module has not been saved IDLE will either prompt the user to save or180autosave, as selected in the General tab of the Idle Settings dialog. If181there is a syntax error, the approximate location is indicated in the182Editor window.</p>183</dd>184</dl>185<dl class="simple" id="python-shell">186<dt>Python Shell</dt><dd><p>Open or wake up the Python Shell window.</p>187</dd>188</dl>189</section>190<section id="shell-menu-shell-window-only">191<h3>Shell menu (Shell window only)<a class="headerlink" href="#shell-menu-shell-window-only" title="Link to this heading">¶</a></h3>192<dl class="simple">193<dt>View Last Restart</dt><dd><p>Scroll the shell window to the last Shell restart.</p>194</dd>195<dt>Restart Shell</dt><dd><p>Restart the shell to clean the environment and reset display and exception handling.</p>196</dd>197<dt>Previous History</dt><dd><p>Cycle through earlier commands in history which match the current entry.</p>198</dd>199<dt>Next History</dt><dd><p>Cycle through later commands in history which match the current entry.</p>200</dd>201<dt>Interrupt Execution</dt><dd><p>Stop a running program.</p>202</dd>203</dl>204</section>205<section id="debug-menu-shell-window-only">206<h3>Debug menu (Shell window only)<a class="headerlink" href="#debug-menu-shell-window-only" title="Link to this heading">¶</a></h3>207<dl class="simple">208<dt>Go to File/Line</dt><dd><p>Look on the current line. with the cursor, and the line above for a filename209and line number. If found, open the file if not already open, and show the210line. Use this to view source lines referenced in an exception traceback211and lines found by Find in Files. Also available in the context menu of212the Shell window and Output windows.</p>213</dd>214</dl>215<dl class="simple" id="index-3">216<dt>Debugger (toggle)</dt><dd><p>When activated, code entered in the Shell or run from an Editor will run217under the debugger. In the Editor, breakpoints can be set with the context218menu. This feature is still incomplete and somewhat experimental.</p>219</dd>220<dt>Stack Viewer</dt><dd><p>Show the stack traceback of the last exception in a tree widget, with221access to locals and globals.</p>222</dd>223<dt>Auto-open Stack Viewer</dt><dd><p>Toggle automatically opening the stack viewer on an unhandled exception.</p>224</dd>225</dl>226</section>227<section id="options-menu-shell-and-editor">228<h3>Options menu (Shell and Editor)<a class="headerlink" href="#options-menu-shell-and-editor" title="Link to this heading">¶</a></h3>229<dl class="simple">230<dt>Configure IDLE</dt><dd><p>Open a configuration dialog and change preferences for the following:231fonts, indentation, keybindings, text color themes, startup windows and232size, additional help sources, and extensions. On macOS, open the233configuration dialog by selecting Preferences in the application234menu. For more details, see235<a class="reference internal" href="#preferences"><span class="std std-ref">Setting preferences</span></a> under Help and preferences.</p>236</dd>237</dl>238<p>Most configuration options apply to all windows or all future windows.239The option items below only apply to the active window.</p>240<dl class="simple">241<dt>Show/Hide Code Context (Editor Window only)</dt><dd><p>Open a pane at the top of the edit window which shows the block context242of the code which has scrolled above the top of the window. See243<a class="reference internal" href="#code-context"><span class="std std-ref">Code Context</span></a> in the Editing and Navigation section244below.</p>245</dd>246<dt>Show/Hide Line Numbers (Editor Window only)</dt><dd><p>Open a column to the left of the edit window which shows the number247of each line of text. The default is off, which may be changed in the248preferences (see <a class="reference internal" href="#preferences"><span class="std std-ref">Setting preferences</span></a>).</p>249</dd>250<dt>Zoom/Restore Height</dt><dd><p>Toggles the window between normal size and maximum height. The initial size251defaults to 40 lines by 80 chars unless changed on the General tab of the252Configure IDLE dialog. The maximum height for a screen is determined by253momentarily maximizing a window the first time one is zoomed on the screen.254Changing screen settings may invalidate the saved height. This toggle has255no effect when a window is maximized.</p>256</dd>257</dl>258</section>259<section id="window-menu-shell-and-editor">260<h3>Window menu (Shell and Editor)<a class="headerlink" href="#window-menu-shell-and-editor" title="Link to this heading">¶</a></h3>261<p>Lists the names of all open windows; select one to bring it to the foreground262(deiconifying it if necessary).</p>263</section>264<section id="help-menu-shell-and-editor">265<h3>Help menu (Shell and Editor)<a class="headerlink" href="#help-menu-shell-and-editor" title="Link to this heading">¶</a></h3>266<dl class="simple">267<dt>About IDLE</dt><dd><p>Display version, copyright, license, credits, and more.</p>268</dd>269<dt>IDLE Help</dt><dd><p>Display this IDLE document, detailing the menu options, basic editing and270navigation, and other tips.</p>271</dd>272<dt>Python Docs</dt><dd><p>Access local Python documentation, if installed, or start a web browser273and open docs.python.org showing the latest Python documentation.</p>274</dd>275<dt>Turtle Demo</dt><dd><p>Run the turtledemo module with example Python code and turtle drawings.</p>276</dd>277</dl>278<p>Additional help sources may be added here with the Configure IDLE dialog under279the General tab. See the <a class="reference internal" href="#help-sources"><span class="std std-ref">Help sources</span></a> subsection below280for more on Help menu choices.</p>281</section>282<section id="context-menus">283<span id="index-4"></span><h3>Context menus<a class="headerlink" href="#context-menus" title="Link to this heading">¶</a></h3>284<p>Open a context menu by right-clicking in a window (Control-click on macOS).285Context menus have the standard clipboard functions also on the Edit menu.</p>286<dl class="simple">287<dt>Cut</dt><dd><p>Copy selection into the system-wide clipboard; then delete the selection.</p>288</dd>289<dt>Copy</dt><dd><p>Copy selection into the system-wide clipboard.</p>290</dd>291<dt>Paste</dt><dd><p>Insert contents of the system-wide clipboard into the current window.</p>292</dd>293</dl>294<p>Editor windows also have breakpoint functions. Lines with a breakpoint set are295specially marked. Breakpoints only have an effect when running under the296debugger. Breakpoints for a file are saved in the user’s <code class="docutils literal notranslate"><span class="pre">.idlerc</span></code>297directory.</p>298<dl class="simple">299<dt>Set Breakpoint</dt><dd><p>Set a breakpoint on the current line.</p>300</dd>301<dt>Clear Breakpoint</dt><dd><p>Clear the breakpoint on that line.</p>302</dd>303</dl>304<p>Shell and Output windows also have the following.</p>305<dl class="simple">306<dt>Go to file/line</dt><dd><p>Same as in Debug menu.</p>307</dd>308</dl>309<p>The Shell window also has an output squeezing facility explained in the <em>Python310Shell window</em> subsection below.</p>311<dl class="simple">312<dt>Squeeze</dt><dd><p>If the cursor is over an output line, squeeze all the output between313the code above and the prompt below down to a ‘Squeezed text’ label.</p>314</dd>315</dl>316</section>317</section>318<section id="editing-and-navigation">319<span id="id1"></span><h2>Editing and Navigation<a class="headerlink" href="#editing-and-navigation" title="Link to this heading">¶</a></h2>320<section id="editor-windows">321<h3>Editor windows<a class="headerlink" href="#editor-windows" title="Link to this heading">¶</a></h3>322<p>IDLE may open editor windows when it starts, depending on settings323and how you start IDLE. Thereafter, use the File menu. There can be only324one open editor window for a given file.</p>325<p>The title bar contains the name of the file, the full path, and the version326of Python and IDLE running the window. The status bar contains the line327number (‘Ln’) and column number (‘Col’). Line numbers start with 1;328column numbers with 0.</p>329<p>IDLE assumes that files with a known .py* extension contain Python code330and that other files do not. Run Python code with the Run menu.</p>331</section>332<section id="key-bindings">333<h3>Key bindings<a class="headerlink" href="#key-bindings" title="Link to this heading">¶</a></h3>334<p>The IDLE insertion cursor is a thin vertical bar between character335positions. When characters are entered, the insertion cursor and336everything to its right moves right one character and337the new character is entered in the new space.</p>338<p>Several non-character keys move the cursor and possibly339delete characters. Deletion does not puts text on the clipboard,340but IDLE has an undo list. Wherever this doc discusses keys,341‘C’ refers to the <kbd class="kbd docutils literal notranslate">Control</kbd> key on Windows and342Unix and the <kbd class="kbd docutils literal notranslate">Command</kbd> key on macOS. (And all such discussions343assume that the keys have not been re-bound to something else.)</p>344<ul class="simple">345<li><p>Arrow keys move the cursor one character or line.</p></li>346<li><p><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">LeftArrow</kbd> and <kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">RightArrow</kbd> moves left or right one word.</p></li>347<li><p><kbd class="kbd docutils literal notranslate">Home</kbd> and <kbd class="kbd docutils literal notranslate">End</kbd> go to the beginning or end of the line.</p></li>348<li><p><kbd class="kbd docutils literal notranslate">Page Up</kbd> and <kbd class="kbd docutils literal notranslate">Page Down</kbd> go up or down one screen.</p></li>349<li><p><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">Home</kbd> and <kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">End</kbd> go to beginning or end of the file.</p></li>350<li><p><kbd class="kbd docutils literal notranslate">Backspace</kbd> and <kbd class="kbd docutils literal notranslate">Del</kbd> (or <kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">d</kbd>) delete the previous351or next character.</p></li>352<li><p><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">Backspace</kbd> and <kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">Del</kbd> delete one word left or right.</p></li>353<li><p><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">k</kbd> deletes (‘kills’) everything to the right.</p></li>354</ul>355<p>Standard keybindings (like <kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">c</kbd> to copy and <kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">v</kbd> to paste)356may work. Keybindings are selected in the Configure IDLE dialog.</p>357</section>358<section id="automatic-indentation">359<h3>Automatic indentation<a class="headerlink" href="#automatic-indentation" title="Link to this heading">¶</a></h3>360<p>After a block-opening statement, the next line is indented by 4 spaces (in the361Python Shell window by one tab). After certain keywords (break, return etc.)362the next line is dedented. In leading indentation, <kbd class="kbd docutils literal notranslate">Backspace</kbd> deletes up363to 4 spaces if they are there. <kbd class="kbd docutils literal notranslate">Tab</kbd> inserts spaces (in the Python364Shell window one tab), number depends on Indent width. Currently, tabs365are restricted to four spaces due to Tcl/Tk limitations.</p>366<p>See also the indent/dedent region commands on the367<a class="reference internal" href="#format-menu"><span class="std std-ref">Format menu</span></a>.</p>368</section>369<section id="search-and-replace">370<h3>Search and Replace<a class="headerlink" href="#search-and-replace" title="Link to this heading">¶</a></h3>371<p>Any selection becomes a search target. However, only selections within372a line work because searches are only performed within lines with the373terminal newline removed. If <code class="docutils literal notranslate"><span class="pre">[x]</span> <span class="pre">Regular</span> <span class="pre">expression</span></code> is checked, the374target is interpreted according to the Python re module.</p>375</section>376<section id="completions">377<span id="id2"></span><h3>Completions<a class="headerlink" href="#completions" title="Link to this heading">¶</a></h3>378<p>Completions are supplied, when requested and available, for module379names, attributes of classes or functions, or filenames. Each request380method displays a completion box with existing names. (See tab381completions below for an exception.) For any box, change the name382being completed and the item highlighted in the box by383typing and deleting characters; by hitting <kbd class="kbd docutils literal notranslate">Up</kbd>, <kbd class="kbd docutils literal notranslate">Down</kbd>,384<kbd class="kbd docutils literal notranslate">PageUp</kbd>, <kbd class="kbd docutils literal notranslate">PageDown</kbd>, <kbd class="kbd docutils literal notranslate">Home</kbd>, and <kbd class="kbd docutils literal notranslate">End</kbd> keys;385and by a single click within the box. Close the box with <kbd class="kbd docutils literal notranslate">Escape</kbd>,386<kbd class="kbd docutils literal notranslate">Enter</kbd>, and double <kbd class="kbd docutils literal notranslate">Tab</kbd> keys or clicks outside the box.387A double click within the box selects and closes.</p>388<p>One way to open a box is to type a key character and wait for a389predefined interval. This defaults to 2 seconds; customize it390in the settings dialog. (To prevent auto popups, set the delay to a391large number of milliseconds, such as 100000000.) For imported module392names or class or function attributes, type ‘.’.393For filenames in the root directory, type <a class="reference internal" href="os.html#os.sep" title="os.sep"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.sep</span></code></a> or394<a class="reference internal" href="os.html#os.altsep" title="os.altsep"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.altsep</span></code></a> immediately after an opening quote. (On Windows,395one can specify a drive first.) Move into subdirectories by typing a396directory name and a separator.</p>397<p>Instead of waiting, or after a box is closed, open a completion box398immediately with Show Completions on the Edit menu. The default hot399key is <kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">space</kbd>. If one types a prefix for the desired name400before opening the box, the first match or near miss is made visible.401The result is the same as if one enters a prefix402after the box is displayed. Show Completions after a quote completes403filenames in the current directory instead of a root directory.</p>404<p>Hitting <kbd class="kbd docutils literal notranslate">Tab</kbd> after a prefix usually has the same effect as Show405Completions. (With no prefix, it indents.) However, if there is only406one match to the prefix, that match is immediately added to the editor407text without opening a box.</p>408<p>Invoking ‘Show Completions’, or hitting <kbd class="kbd docutils literal notranslate">Tab</kbd> after a prefix,409outside of a string and without a preceding ‘.’ opens a box with410keywords, builtin names, and available module-level names.</p>411<p>When editing code in an editor (as oppose to Shell), increase the412available module-level names by running your code413and not restarting the Shell thereafter. This is especially useful414after adding imports at the top of a file. This also increases415possible attribute completions.</p>416<p>Completion boxes initially exclude names beginning with ‘_’ or, for417modules, not included in ‘__all__’. The hidden names can be accessed418by typing ‘_’ after ‘.’, either before or after the box is opened.</p>419</section>420<section id="calltips">421<span id="id3"></span><h3>Calltips<a class="headerlink" href="#calltips" title="Link to this heading">¶</a></h3>422<p>A calltip is shown automatically when one types <kbd class="kbd docutils literal notranslate">(</kbd> after the name423of an <em>accessible</em> function. A function name expression may include424dots and subscripts. A calltip remains until it is clicked, the cursor425is moved out of the argument area, or <kbd class="kbd docutils literal notranslate">)</kbd> is typed. Whenever the426cursor is in the argument part of a definition, select Edit and “Show427Call Tip” on the menu or enter its shortcut to display a calltip.</p>428<p>The calltip consists of the function’s signature and docstring up to429the latter’s first blank line or the fifth non-blank line. (Some builtin430functions lack an accessible signature.) A ‘/’ or ‘*’ in the signature431indicates that the preceding or following arguments are passed by432position or name (keyword) only. Details are subject to change.</p>433<p>In Shell, the accessible functions depends on what modules have been434imported into the user process, including those imported by Idle itself,435and which definitions have been run, all since the last restart.</p>436<p>For example, restart the Shell and enter <code class="docutils literal notranslate"><span class="pre">itertools.count(</span></code>. A calltip437appears because Idle imports itertools into the user process for its own438use. (This could change.) Enter <code class="docutils literal notranslate"><span class="pre">turtle.write(</span></code> and nothing appears.439Idle does not itself import turtle. The menu entry and shortcut also do440nothing. Enter <code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre">turtle</span></code>. Thereafter, <code class="docutils literal notranslate"><span class="pre">turtle.write(</span></code>441will display a calltip.</p>442<p>In an editor, import statements have no effect until one runs the file.443One might want to run a file after writing import statements, after444adding function definitions, or after opening an existing file.</p>445</section>446<section id="format-block">447<span id="id4"></span><h3>Format block<a class="headerlink" href="#format-block" title="Link to this heading">¶</a></h3>448<p>Reformat Paragraph rewraps a block (‘paragraph’) of contiguous equally449indented non-blank comments, a similar block of text within a multiline450string, or a selected subset of either.451If needed, add a blank line to separate string from code.452Partial lines in a selection expand to complete lines.453The resulting lines have the same indent as before454but have maximum total length of N columns (characters).455Change the default N of 72 on the Window tab of IDLE Settings.</p>456</section>457<section id="code-context">458<span id="id5"></span><h3>Code Context<a class="headerlink" href="#code-context" title="Link to this heading">¶</a></h3>459<p>Within an editor window containing Python code, code context can be toggled460in order to show or hide a pane at the top of the window. When shown, this461pane freezes the opening lines for block code, such as those beginning with462<code class="docutils literal notranslate"><span class="pre">class</span></code>, <code class="docutils literal notranslate"><span class="pre">def</span></code>, or <code class="docutils literal notranslate"><span class="pre">if</span></code> keywords, that would have otherwise scrolled463out of view. The size of the pane will be expanded and contracted as needed464to show the all current levels of context, up to the maximum number of465lines defined in the Configure IDLE dialog (which defaults to 15). If there466are no current context lines and the feature is toggled on, a single blank467line will display. Clicking on a line in the context pane will move that468line to the top of the editor.</p>469<p>The text and background colors for the context pane can be configured under470the Highlights tab in the Configure IDLE dialog.</p>471</section>472<section id="shell-window">473<h3>Shell window<a class="headerlink" href="#shell-window" title="Link to this heading">¶</a></h3>474<p>In IDLE’s Shell, enter, edit, and recall complete statements. (Most475consoles and terminals only work with a single physical line at a time).</p>476<p>Submit a single-line statement for execution by hitting <kbd class="kbd docutils literal notranslate">Return</kbd>477with the cursor anywhere on the line. If a line is extended with478Backslash (<kbd class="kbd docutils literal notranslate">\</kbd>), the cursor must be on the last physical line.479Submit a multi-line compound statement by entering a blank line after480the statement.</p>481<p>When one pastes code into Shell, it is not compiled and possibly executed482until one hits <kbd class="kbd docutils literal notranslate">Return</kbd>, as specified above.483One may edit pasted code first.484If one pastes more than one statement into Shell, the result will be a485<a class="reference internal" href="exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a> when multiple statements are compiled as if they were one.</p>486<p>Lines containing <code class="docutils literal notranslate"><span class="pre">RESTART</span></code> mean that the user execution process has been487re-started. This occurs when the user execution process has crashed,488when one requests a restart on the Shell menu, or when one runs code489in an editor window.</p>490<p>The editing features described in previous subsections work when entering491code interactively. IDLE’s Shell window also responds to the following:</p>492<ul class="simple">493<li><p><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">c</kbd> attempts to interrupt statement execution (but may fail).</p></li>494<li><p><kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">d</kbd> closes Shell if typed at a <code class="docutils literal notranslate"><span class="pre">>>></span></code> prompt.</p></li>495<li><p><kbd class="kbd docutils literal notranslate">Alt</kbd>-<kbd class="kbd docutils literal notranslate">p</kbd> and <kbd class="kbd docutils literal notranslate">Alt</kbd>-<kbd class="kbd docutils literal notranslate">n</kbd> (<kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">p</kbd> and <kbd class="kbd docutils literal notranslate">C</kbd>-<kbd class="kbd docutils literal notranslate">n</kbd> on macOS)496retrieve to the current prompt the previous or next previously497entered statement that matches anything already typed.</p></li>498<li><p><kbd class="kbd docutils literal notranslate">Return</kbd> while the cursor is on any previous statement499appends the latter to anything already typed at the prompt.</p></li>500</ul>501</section>502<section id="text-colors">503<h3>Text colors<a class="headerlink" href="#text-colors" title="Link to this heading">¶</a></h3>504<p>Idle defaults to black on white text, but colors text with special meanings.505For the shell, these are shell output, shell error, user output, and506user error. For Python code, at the shell prompt or in an editor, these are507keywords, builtin class and function names, names following <code class="docutils literal notranslate"><span class="pre">class</span></code> and508<code class="docutils literal notranslate"><span class="pre">def</span></code>, strings, and comments. For any text window, these are the cursor (when509present), found text (when possible), and selected text.</p>510<p>IDLE also highlights the <a class="reference internal" href="../reference/lexical_analysis.html#soft-keywords"><span class="std std-ref">soft keywords</span></a> <a class="reference internal" href="../reference/compound_stmts.html#match"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">match</span></code></a>,511<a class="reference internal" href="../reference/compound_stmts.html#match"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">case</span></code></a>, and <a class="reference internal" href="../reference/compound_stmts.html#wildcard-patterns"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">_</span></code></a> in512pattern-matching statements. However, this highlighting is not perfect and513will be incorrect in some rare cases, including some <code class="docutils literal notranslate"><span class="pre">_</span></code>-s in <code class="docutils literal notranslate"><span class="pre">case</span></code>514patterns.</p>515<p>Text coloring is done in the background, so uncolorized text is occasionally516visible. To change the color scheme, use the Configure IDLE dialog517Highlighting tab. The marking of debugger breakpoint lines in the editor and518text in popups and dialogs is not user-configurable.</p>519</section>520</section>521<section id="startup-and-code-execution">522<h2>Startup and Code Execution<a class="headerlink" href="#startup-and-code-execution" title="Link to this heading">¶</a></h2>523<p>Upon startup with the <code class="docutils literal notranslate"><span class="pre">-s</span></code> option, IDLE will execute the file referenced by524the environment variables <span class="target" id="index-5"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">IDLESTARTUP</span></code> or <span class="target" id="index-6"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONSTARTUP"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONSTARTUP</span></code></a>.525IDLE first checks for <code class="docutils literal notranslate"><span class="pre">IDLESTARTUP</span></code>; if <code class="docutils literal notranslate"><span class="pre">IDLESTARTUP</span></code> is present the file526referenced is run. If <code class="docutils literal notranslate"><span class="pre">IDLESTARTUP</span></code> is not present, IDLE checks for527<code class="docutils literal notranslate"><span class="pre">PYTHONSTARTUP</span></code>. Files referenced by these environment variables are528convenient places to store functions that are used frequently from the IDLE529shell, or for executing import statements to import common modules.</p>530<p>In addition, <code class="docutils literal notranslate"><span class="pre">Tk</span></code> also loads a startup file if it is present. Note that the531Tk file is loaded unconditionally. This additional file is <code class="docutils literal notranslate"><span class="pre">.Idle.py</span></code> and is532looked for in the user’s home directory. Statements in this file will be533executed in the Tk namespace, so this file is not useful for importing534functions to be used from IDLE’s Python shell.</p>535<section id="command-line-usage">536<span id="idlelib-cli"></span><h3>Command-line usage<a class="headerlink" href="#command-line-usage" title="Link to this heading">¶</a></h3>537<p>IDLE can be invoked from the command line with various options. The general syntax is:</p>538<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>python<span class="w"> </span>-m<span class="w"> </span>idlelib<span class="w"> </span><span class="o">[</span>options<span class="o">]</span><span class="w"> </span><span class="o">[</span>file<span class="w"> </span>...<span class="o">]</span>539</pre></div>540</div>541<p>The following options are available:</p>542<dl class="std option">543<dt class="sig sig-object std" id="cmdoption-idle-c">544<span class="sig-name descname"><span class="pre">-c</span></span><span class="sig-prename descclassname"> <span class="pre"><command></span></span><a class="headerlink" href="#cmdoption-idle-c" title="Link to this definition">¶</a></dt>545<dd><p>Run the specified Python command in the shell window.546For example, pass <code class="docutils literal notranslate"><span class="pre">-c</span> <span class="pre">"print('Hello,</span> <span class="pre">World!')"</span></code>.547On Windows, the outer quotes must be double quotes as shown.</p>548</dd></dl>549 550<dl class="std option">551<dt class="sig sig-object std" id="cmdoption-idle-d">552<span class="sig-name descname"><span class="pre">-d</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-idle-d" title="Link to this definition">¶</a></dt>553<dd><p>Enable the debugger and open the shell window.</p>554</dd></dl>555 556<dl class="std option">557<dt class="sig sig-object std" id="cmdoption-idle-e">558<span class="sig-name descname"><span class="pre">-e</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-idle-e" title="Link to this definition">¶</a></dt>559<dd><p>Open an editor window.</p>560</dd></dl>561 562<dl class="std option">563<dt class="sig sig-object std" id="cmdoption-idle-h">564<span class="sig-name descname"><span class="pre">-h</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-idle-h" title="Link to this definition">¶</a></dt>565<dd><p>Print a help message with legal combinations of options and exit.</p>566</dd></dl>567 568<dl class="std option">569<dt class="sig sig-object std" id="cmdoption-idle-i">570<span class="sig-name descname"><span class="pre">-i</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-idle-i" title="Link to this definition">¶</a></dt>571<dd><p>Open a shell window.</p>572</dd></dl>573 574<dl class="std option">575<dt class="sig sig-object std" id="cmdoption-idle-r">576<span class="sig-name descname"><span class="pre">-r</span></span><span class="sig-prename descclassname"> <span class="pre"><file></span></span><a class="headerlink" href="#cmdoption-idle-r" title="Link to this definition">¶</a></dt>577<dd><p>Run the specified file in the shell window.</p>578</dd></dl>579 580<dl class="std option">581<dt class="sig sig-object std" id="cmdoption-idle-s">582<span class="sig-name descname"><span class="pre">-s</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-idle-s" title="Link to this definition">¶</a></dt>583<dd><p>Run the startup file (as defined by the environment variables <span class="target" id="index-7"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">IDLESTARTUP</span></code> or <span class="target" id="index-8"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONSTARTUP"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONSTARTUP</span></code></a>) before opening the shell window.</p>584</dd></dl>585 586<dl class="std option">587<dt class="sig sig-object std" id="cmdoption-idle-t">588<span class="sig-name descname"><span class="pre">-t</span></span><span class="sig-prename descclassname"> <span class="pre"><title></span></span><a class="headerlink" href="#cmdoption-idle-t" title="Link to this definition">¶</a></dt>589<dd><p>Set the title of the shell window.</p>590</dd></dl>591 592<dl class="std option">593<dt class="sig sig-object std" id="cmdoption-idle-0">594<span class="sig-name descname"><span class="pre">-</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-idle-0" title="Link to this definition">¶</a></dt>595<dd><p>Read and execute standard input in the shell window. This option must be the last one before any arguments.</p>596</dd></dl>597 598<p>If arguments are provided:</p>599<ul class="simple">600<li><p>If <code class="docutils literal notranslate"><span class="pre">-</span></code>, <code class="docutils literal notranslate"><span class="pre">-c</span></code>, or <code class="docutils literal notranslate"><span class="pre">-r</span></code> is used, all arguments are placed in <code class="docutils literal notranslate"><span class="pre">sys.argv[1:]</span></code>,601and <code class="docutils literal notranslate"><span class="pre">sys.argv[0]</span></code> is set to <code class="docutils literal notranslate"><span class="pre">''</span></code>, <code class="docutils literal notranslate"><span class="pre">'-c'</span></code>, or <code class="docutils literal notranslate"><span class="pre">'-r'</span></code> respectively.602No editor window is opened, even if that is the default set in the <em>Options</em> dialog.</p></li>603<li><p>Otherwise, arguments are treated as files to be opened for editing, and <code class="docutils literal notranslate"><span class="pre">sys.argv</span></code> reflects the arguments passed to IDLE itself.</p></li>604</ul>605</section>606<section id="startup-failure">607<h3>Startup failure<a class="headerlink" href="#startup-failure" title="Link to this heading">¶</a></h3>608<p>IDLE uses a socket to communicate between the IDLE GUI process and the user609code execution process. A connection must be established whenever the Shell610starts or restarts. (The latter is indicated by a divider line that says611‘RESTART’). If the user process fails to connect to the GUI process, it612usually displays a <code class="docutils literal notranslate"><span class="pre">Tk</span></code> error box with a ‘cannot connect’ message613that directs the user here. It then exits.</p>614<p>One specific connection failure on Unix systems results from615misconfigured masquerading rules somewhere in a system’s network setup.616When IDLE is started from a terminal, one will see a message starting617with <code class="docutils literal notranslate"><span class="pre">**</span> <span class="pre">Invalid</span> <span class="pre">host:</span></code>.618The valid value is <code class="docutils literal notranslate"><span class="pre">127.0.0.1</span> <span class="pre">(idlelib.rpc.LOCALHOST)</span></code>.619One can diagnose with <code class="docutils literal notranslate"><span class="pre">tcpconnect</span> <span class="pre">-irv</span> <span class="pre">127.0.0.1</span> <span class="pre">6543</span></code> in one620terminal window and <code class="docutils literal notranslate"><span class="pre">tcplisten</span> <span class="pre"><same</span> <span class="pre">args></span></code> in another.</p>621<p>A common cause of failure is a user-written file with the same name as a622standard library module, such as <em>random.py</em> and <em>tkinter.py</em>. When such a623file is located in the same directory as a file that is about to be run,624IDLE cannot import the stdlib file. The current fix is to rename the625user file.</p>626<p>Though less common than in the past, an antivirus or firewall program may627stop the connection. If the program cannot be taught to allow the628connection, then it must be turned off for IDLE to work. It is safe to629allow this internal connection because no data is visible on external630ports. A similar problem is a network mis-configuration that blocks631connections.</p>632<p>Python installation issues occasionally stop IDLE: multiple versions can633clash, or a single installation might need admin access. If one undo the634clash, or cannot or does not want to run as admin, it might be easiest to635completely remove Python and start over.</p>636<p>A zombie pythonw.exe process could be a problem. On Windows, use Task637Manager to check for one and stop it if there is. Sometimes a restart638initiated by a program crash or Keyboard Interrupt (control-C) may fail639to connect. Dismissing the error box or using Restart Shell on the Shell640menu may fix a temporary problem.</p>641<p>When IDLE first starts, it attempts to read user configuration files in642<code class="docutils literal notranslate"><span class="pre">~/.idlerc/</span></code> (~ is one’s home directory). If there is a problem, an error643message should be displayed. Leaving aside random disk glitches, this can644be prevented by never editing the files by hand. Instead, use the645configuration dialog, under Options. Once there is an error in a user646configuration file, the best solution may be to delete it and start over647with the settings dialog.</p>648<p>If IDLE quits with no message, and it was not started from a console, try649starting it from a console or terminal (<code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-m</span> <span class="pre">idlelib</span></code>) and see if650this results in an error message.</p>651<p>On Unix-based systems with tcl/tk older than <code class="docutils literal notranslate"><span class="pre">8.6.11</span></code> (see652<code class="docutils literal notranslate"><span class="pre">About</span> <span class="pre">IDLE</span></code>) certain characters of certain fonts can cause653a tk failure with a message to the terminal. This can happen either654if one starts IDLE to edit a file with such a character or later655when entering such a character. If one cannot upgrade tcl/tk,656then re-configure IDLE to use a font that works better.</p>657</section>658<section id="running-user-code">659<h3>Running user code<a class="headerlink" href="#running-user-code" title="Link to this heading">¶</a></h3>660<p>With rare exceptions, the result of executing Python code with IDLE is661intended to be the same as executing the same code by the default method,662directly with Python in a text-mode system console or terminal window.663However, the different interface and operation occasionally affect664visible results. For instance, <code class="docutils literal notranslate"><span class="pre">sys.modules</span></code> starts with more entries,665and <code class="docutils literal notranslate"><span class="pre">threading.active_count()</span></code> returns 2 instead of 1.</p>666<p>By default, IDLE runs user code in a separate OS process rather than in667the user interface process that runs the shell and editor. In the execution668process, it replaces <code class="docutils literal notranslate"><span class="pre">sys.stdin</span></code>, <code class="docutils literal notranslate"><span class="pre">sys.stdout</span></code>, and <code class="docutils literal notranslate"><span class="pre">sys.stderr</span></code>669with objects that get input from and send output to the Shell window.670The original values stored in <code class="docutils literal notranslate"><span class="pre">sys.__stdin__</span></code>, <code class="docutils literal notranslate"><span class="pre">sys.__stdout__</span></code>, and671<code class="docutils literal notranslate"><span class="pre">sys.__stderr__</span></code> are not touched, but may be <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>672<p>Sending print output from one process to a text widget in another is673slower than printing to a system terminal in the same process.674This has the most effect when printing multiple arguments, as the string675for each argument, each separator, the newline are sent separately.676For development, this is usually not a problem, but if one wants to677print faster in IDLE, format and join together everything one wants678displayed together and then print a single string. Both format strings679and <a class="reference internal" href="stdtypes.html#str.join" title="str.join"><code class="xref py py-meth docutils literal notranslate"><span class="pre">str.join()</span></code></a> can help combine fields and lines.</p>680<p>IDLE’s standard stream replacements are not inherited by subprocesses681created in the execution process, whether directly by user code or by682modules such as multiprocessing. If such subprocess use <code class="docutils literal notranslate"><span class="pre">input</span></code> from683sys.stdin or <code class="docutils literal notranslate"><span class="pre">print</span></code> or <code class="docutils literal notranslate"><span class="pre">write</span></code> to sys.stdout or sys.stderr,684IDLE should be started in a command line window. (On Windows,685use <code class="docutils literal notranslate"><span class="pre">python</span></code> or <code class="docutils literal notranslate"><span class="pre">py</span></code> rather than <code class="docutils literal notranslate"><span class="pre">pythonw</span></code> or <code class="docutils literal notranslate"><span class="pre">pyw</span></code>.)686The secondary subprocess687will then be attached to that window for input and output.</p>688<p>If <code class="docutils literal notranslate"><span class="pre">sys</span></code> is reset by user code, such as with <code class="docutils literal notranslate"><span class="pre">importlib.reload(sys)</span></code>,689IDLE’s changes are lost and input from the keyboard and output to the screen690will not work correctly.</p>691<p>When Shell has the focus, it controls the keyboard and screen. This is692normally transparent, but functions that directly access the keyboard693and screen will not work. These include system-specific functions that694determine whether a key has been pressed and if so, which.</p>695<p>The IDLE code running in the execution process adds frames to the call stack696that would not be there otherwise. IDLE wraps <code class="docutils literal notranslate"><span class="pre">sys.getrecursionlimit</span></code> and697<code class="docutils literal notranslate"><span class="pre">sys.setrecursionlimit</span></code> to reduce the effect of the additional stack698frames.</p>699<p>When user code raises SystemExit either directly or by calling sys.exit,700IDLE returns to a Shell prompt instead of exiting.</p>701</section>702<section id="user-output-in-shell">703<h3>User output in Shell<a class="headerlink" href="#user-output-in-shell" title="Link to this heading">¶</a></h3>704<p>When a program outputs text, the result is determined by the705corresponding output device. When IDLE executes user code, <code class="docutils literal notranslate"><span class="pre">sys.stdout</span></code>706and <code class="docutils literal notranslate"><span class="pre">sys.stderr</span></code> are connected to the display area of IDLE’s Shell. Some of707its features are inherited from the underlying Tk Text widget. Others708are programmed additions. Where it matters, Shell is designed for development709rather than production runs.</p>710<p>For instance, Shell never throws away output. A program that sends unlimited711output to Shell will eventually fill memory, resulting in a memory error.712In contrast, some system text windows only keep the last n lines of output.713A Windows console, for instance, keeps a user-settable 1 to 9999 lines,714with 300 the default.</p>715<p>A Tk Text widget, and hence IDLE’s Shell, displays characters (codepoints) in716the BMP (Basic Multilingual Plane) subset of Unicode. Which characters are717displayed with a proper glyph and which with a replacement box depends on the718operating system and installed fonts. Tab characters cause the following text719to begin after the next tab stop. (They occur every 8 ‘characters’). Newline720characters cause following text to appear on a new line. Other control721characters are ignored or displayed as a space, box, or something else,722depending on the operating system and font. (Moving the text cursor through723such output with arrow keys may exhibit some surprising spacing behavior.)</p>724<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">s</span> <span class="o">=</span> <span class="s1">'a</span><span class="se">\t</span><span class="s1">b</span><span class="se">\a</span><span class="s1"><</span><span class="se">\x02</span><span class="s1">><</span><span class="se">\r</span><span class="s1">></span><span class="se">\b</span><span class="s1">c</span><span class="se">\n</span><span class="s1">d'</span> <span class="c1"># Enter 22 chars.</span>725<span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>726<span class="go">14</span>727<span class="gp">>>> </span><span class="n">s</span> <span class="c1"># Display repr(s)</span>728<span class="go">'a\tb\x07<\x02><\r>\x08c\nd'</span>729<span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">end</span><span class="o">=</span><span class="s1">''</span><span class="p">)</span> <span class="c1"># Display s as is.</span>730<span class="go"># Result varies by OS and font. Try it.</span>731</pre></div>732</div>733<p>The <code class="docutils literal notranslate"><span class="pre">repr</span></code> function is used for interactive echo of expression734values. It returns an altered version of the input string in which735control codes, some BMP codepoints, and all non-BMP codepoints are736replaced with escape codes. As demonstrated above, it allows one to737identify the characters in a string, regardless of how they are displayed.</p>738<p>Normal and error output are generally kept separate (on separate lines)739from code input and each other. They each get different highlight colors.</p>740<p>For SyntaxError tracebacks, the normal ‘^’ marking where the error was741detected is replaced by coloring the text with an error highlight.742When code run from a file causes other exceptions, one may right click743on a traceback line to jump to the corresponding line in an IDLE editor.744The file will be opened if necessary.</p>745<p>Shell has a special facility for squeezing output lines down to a746‘Squeezed text’ label. This is done automatically747for output over N lines (N = 50 by default).748N can be changed in the PyShell section of the General749page of the Settings dialog. Output with fewer lines can be squeezed by750right clicking on the output. This can be useful lines long enough to slow751down scrolling.</p>752<p>Squeezed output is expanded in place by double-clicking the label.753It can also be sent to the clipboard or a separate view window by754right-clicking the label.</p>755</section>756<section id="developing-tkinter-applications">757<h3>Developing tkinter applications<a class="headerlink" href="#developing-tkinter-applications" title="Link to this heading">¶</a></h3>758<p>IDLE is intentionally different from standard Python in order to759facilitate development of tkinter programs. Enter <code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre">tkinter</span> <span class="pre">as</span> <span class="pre">tk;</span>760<span class="pre">root</span> <span class="pre">=</span> <span class="pre">tk.Tk()</span></code> in standard Python and nothing appears. Enter the same761in IDLE and a tk window appears. In standard Python, one must also enter762<code class="docutils literal notranslate"><span class="pre">root.update()</span></code> to see the window. IDLE does the equivalent in the763background, about 20 times a second, which is about every 50 milliseconds.764Next enter <code class="docutils literal notranslate"><span class="pre">b</span> <span class="pre">=</span> <span class="pre">tk.Button(root,</span> <span class="pre">text='button');</span> <span class="pre">b.pack()</span></code>. Again,765nothing visibly changes in standard Python until one enters <code class="docutils literal notranslate"><span class="pre">root.update()</span></code>.</p>766<p>Most tkinter programs run <code class="docutils literal notranslate"><span class="pre">root.mainloop()</span></code>, which usually does not767return until the tk app is destroyed. If the program is run with768<code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-i</span></code> or from an IDLE editor, a <code class="docutils literal notranslate"><span class="pre">>>></span></code> shell prompt does not769appear until <code class="docutils literal notranslate"><span class="pre">mainloop()</span></code> returns, at which time there is nothing left770to interact with.</p>771<p>When running a tkinter program from an IDLE editor, one can comment out772the mainloop call. One then gets a shell prompt immediately and can773interact with the live application. One just has to remember to774re-enable the mainloop call when running in standard Python.</p>775</section>776<section id="running-without-a-subprocess">777<h3>Running without a subprocess<a class="headerlink" href="#running-without-a-subprocess" title="Link to this heading">¶</a></h3>778<p>By default, IDLE executes user code in a separate subprocess via a socket,779which uses the internal loopback interface. This connection is not780externally visible and no data is sent to or received from the internet.781If firewall software complains anyway, you can ignore it.</p>782<p>If the attempt to make the socket connection fails, Idle will notify you.783Such failures are sometimes transient, but if persistent, the problem784may be either a firewall blocking the connection or misconfiguration of785a particular system. Until the problem is fixed, one can run Idle with786the -n command line switch.</p>787<p>If IDLE is started with the -n command line switch it will run in a788single process and will not create the subprocess which runs the RPC789Python execution server. This can be useful if Python cannot create790the subprocess or the RPC socket interface on your platform. However,791in this mode user code is not isolated from IDLE itself. Also, the792environment is not restarted when Run/Run Module (F5) is selected. If793your code has been modified, you must reload() the affected modules and794re-import any specific items (e.g. from foo import baz) if the changes795are to take effect. For these reasons, it is preferable to run IDLE796with the default subprocess if at all possible.</p>797<div class="deprecated">798<p><span class="versionmodified deprecated">Deprecated since version 3.4.</span></p>799</div>800</section>801</section>802<section id="help-and-preferences">803<h2>Help and Preferences<a class="headerlink" href="#help-and-preferences" title="Link to this heading">¶</a></h2>804<section id="help-sources">805<span id="id6"></span><h3>Help sources<a class="headerlink" href="#help-sources" title="Link to this heading">¶</a></h3>806<p>Help menu entry “IDLE Help” displays a formatted html version of the807IDLE chapter of the Library Reference. The result, in a read-only808tkinter text window, is close to what one sees in a web browser.809Navigate through the text with a mousewheel,810the scrollbar, or up and down arrow keys held down.811Or click the TOC (Table of Contents) button and select a section812header in the opened box.</p>813<p>Help menu entry “Python Docs” opens the extensive sources of help,814including tutorials, available at <code class="docutils literal notranslate"><span class="pre">docs.python.org/x.y</span></code>, where ‘x.y’815is the currently running Python version. If your system816has an off-line copy of the docs (this may be an installation option),817that will be opened instead.</p>818<p>Selected URLs can be added or removed from the help menu at any time using the819General tab of the Configure IDLE dialog.</p>820</section>821<section id="setting-preferences">822<span id="preferences"></span><h3>Setting preferences<a class="headerlink" href="#setting-preferences" title="Link to this heading">¶</a></h3>823<p>The font preferences, highlighting, keys, and general preferences can be824changed via Configure IDLE on the Option menu.825Non-default user settings are saved in a <code class="docutils literal notranslate"><span class="pre">.idlerc</span></code> directory in the user’s826home directory. Problems caused by bad user configuration files are solved827by editing or deleting one or more of the files in <code class="docutils literal notranslate"><span class="pre">.idlerc</span></code>.</p>828<p>On the Font tab, see the text sample for the effect of font face and size829on multiple characters in multiple languages. Edit the sample to add830other characters of personal interest. Use the sample to select831monospaced fonts. If particular characters have problems in Shell or an832editor, add them to the top of the sample and try changing first size833and then font.</p>834<p>On the Highlights and Keys tab, select a built-in or custom color theme835and key set. To use a newer built-in color theme or key set with older836IDLEs, save it as a new custom theme or key set and it well be accessible837to older IDLEs.</p>838</section>839<section id="idle-on-macos">840<h3>IDLE on macOS<a class="headerlink" href="#idle-on-macos" title="Link to this heading">¶</a></h3>841<p>Under System Preferences: Dock, one can set “Prefer tabs when opening842documents” to “Always”. This setting is not compatible with the tk/tkinter843GUI framework used by IDLE, and it breaks a few IDLE features.</p>844</section>845<section id="extensions">846<h3>Extensions<a class="headerlink" href="#extensions" title="Link to this heading">¶</a></h3>847<p>IDLE contains an extension facility. Preferences for extensions can be848changed with the Extensions tab of the preferences dialog. See the849beginning of config-extensions.def in the idlelib directory for further850information. The only current default extension is zzdummy, an example851also used for testing.</p>852</section>853</section>854<section id="module-idlelib">855<span id="idlelib-implementation-of-idle-application"></span><h2>idlelib — implementation of IDLE application<a class="headerlink" href="#module-idlelib" title="Link to this heading">¶</a></h2>856<p><strong>Source code:</strong> <a class="extlink-source reference external" href="https://github.com/python/cpython/tree/main/Lib/idlelib">Lib/idlelib</a></p>857<hr class="docutils" />858<p>The Lib/idlelib package implements the IDLE application. See the rest859of this page for how to use IDLE.</p>860<p>The files in idlelib are described in idlelib/README.txt. Access it861either in idlelib or click Help => About IDLE on the IDLE menu. This862file also maps IDLE menu items to the code that implements the item.863Except for files listed under ‘Startup’, the idlelib code is ‘private’ in864sense that feature changes can be backported (see <span class="target" id="index-9"></span><a class="pep reference external" href="https://peps.python.org/pep-0434/"><strong>PEP 434</strong></a>).</p>865</section>866</section>867 868 869 