Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1 | .. _idle: |
| 2 | |
Ned Deily | 50afcc0 | 2015-02-06 15:42:06 +1100 | [diff] [blame] | 3 | IDLE |
| 4 | ==== |
| 5 | |
Terry Jan Reedy | fa089b9 | 2016-06-11 15:02:54 -0400 | [diff] [blame] | 6 | .. moduleauthor:: Guido van Rossum <guido@python.org> |
| 7 | |
| 8 | **Source code:** :source:`Lib/idlelib/` |
| 9 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 10 | .. index:: |
Christian Heimes | 5b5e81c | 2007-12-31 16:14:33 +0000 | [diff] [blame] | 11 | single: IDLE |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 12 | single: Python Editor |
| 13 | single: Integrated Development Environment |
| 14 | |
Terry Jan Reedy | fa089b9 | 2016-06-11 15:02:54 -0400 | [diff] [blame] | 15 | -------------- |
Terry Jan Reedy | f568494 | 2014-12-04 00:54:59 -0500 | [diff] [blame] | 16 | |
Terry Jan Reedy | d470527 | 2015-10-02 23:22:59 -0400 | [diff] [blame] | 17 | IDLE is Python's Integrated Development and Learning Environment. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 18 | |
| 19 | IDLE has the following features: |
| 20 | |
Georg Brandl | ac6060c | 2008-05-17 18:44:45 +0000 | [diff] [blame] | 21 | * coded in 100% pure Python, using the :mod:`tkinter` GUI toolkit |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 22 | |
Terry Jan Reedy | 0053c47 | 2015-09-24 03:09:43 -0400 | [diff] [blame] | 23 | * cross-platform: works mostly the same on Windows, Unix, and Mac OS X |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 24 | |
Terry Jan Reedy | 6e10ec5 | 2015-09-23 20:00:33 -0400 | [diff] [blame] | 25 | * Python shell window (interactive interpreter) with colorizing |
| 26 | of code input, output, and error messages |
| 27 | |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 28 | * multi-window text editor with multiple undo, Python colorizing, |
Terry Jan Reedy | 6e10ec5 | 2015-09-23 20:00:33 -0400 | [diff] [blame] | 29 | smart indent, call tips, auto completion, and other features |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 30 | |
Terry Jan Reedy | 6e10ec5 | 2015-09-23 20:00:33 -0400 | [diff] [blame] | 31 | * search within any window, replace within editor windows, and search |
| 32 | through multiple files (grep) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 33 | |
Terry Jan Reedy | 6e10ec5 | 2015-09-23 20:00:33 -0400 | [diff] [blame] | 34 | * debugger with persistent breakpoints, stepping, and viewing |
| 35 | of global and local namespaces |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 36 | |
Terry Jan Reedy | 6e10ec5 | 2015-09-23 20:00:33 -0400 | [diff] [blame] | 37 | * configuration, browsers, and other dialogs |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 38 | |
| 39 | Menus |
| 40 | ----- |
| 41 | |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 42 | IDLE has two main window types, the Shell window and the Editor window. It is |
| 43 | possible to have multiple editor windows simultaneously. Output windows, such |
| 44 | as used for Edit / Find in Files, are a subtype of edit window. They currently |
| 45 | have the same top menu as Editor windows but a different default title and |
| 46 | context menu. |
| 47 | |
| 48 | IDLE's menus dynamically change based on which window is currently selected. |
| 49 | Each menu documented below indicates which window type it is associated with. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 50 | |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 51 | File menu (Shell and Editor) |
| 52 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 53 | |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 54 | New File |
| 55 | Create a new file editing window. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 56 | |
| 57 | Open... |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 58 | Open an existing file with an Open dialog. |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 59 | |
| 60 | Recent Files |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 61 | Open a list of recent files. Click one to open it. |
| 62 | |
| 63 | Open Module... |
| 64 | Open an existing module (searches sys.path). |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 65 | |
Terry Jan Reedy | f568494 | 2014-12-04 00:54:59 -0500 | [diff] [blame] | 66 | .. index:: |
| 67 | single: Class browser |
| 68 | single: Path browser |
| 69 | |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 70 | Class Browser |
| 71 | Show functions, classes, and methods in the current Editor file in a |
| 72 | tree structure. In the shell, open a module first. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 73 | |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 74 | Path Browser |
| 75 | Show sys.path directories, modules, functions, classes and methods in a |
| 76 | tree structure. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 77 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 78 | Save |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 79 | Save the current window to the associated file, if there is one. Windows |
| 80 | that have been changed since being opened or last saved have a \* before |
| 81 | and after the window title. If there is no associated file, |
| 82 | do Save As instead. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 83 | |
| 84 | Save As... |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 85 | Save the current window with a Save As dialog. The file saved becomes the |
| 86 | new associated file for the window. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 87 | |
| 88 | Save Copy As... |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 89 | Save the current window to different file without changing the associated |
| 90 | file. |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 91 | |
| 92 | Print Window |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 93 | Print the current window to the default printer. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 94 | |
| 95 | Close |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 96 | Close the current window (ask to save if unsaved). |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 97 | |
| 98 | Exit |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 99 | Close all windows and quit IDLE (ask to save unsaved windows). |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 100 | |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 101 | Edit menu (Shell and Editor) |
| 102 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 103 | |
| 104 | Undo |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 105 | Undo the last change to the current window. A maximum of 1000 changes may |
| 106 | be undone. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 107 | |
| 108 | Redo |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 109 | Redo the last undone change to the current window. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 110 | |
| 111 | Cut |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 112 | Copy selection into the system-wide clipboard; then delete the selection. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 113 | |
| 114 | Copy |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 115 | Copy selection into the system-wide clipboard. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 116 | |
| 117 | Paste |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 118 | Insert contents of the system-wide clipboard into the current window. |
| 119 | |
| 120 | The clipboard functions are also available in context menus. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 121 | |
| 122 | Select All |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 123 | Select the entire contents of the current window. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 124 | |
| 125 | Find... |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 126 | Open a search dialog with many options |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 127 | |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 128 | Find Again |
| 129 | Repeat the last search, if there is one. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 130 | |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 131 | Find Selection |
| 132 | Search for the currently selected string, if there is one. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 133 | |
| 134 | Find in Files... |
Serhiy Storchaka | 6a7b3a7 | 2016-04-17 08:32:47 +0300 | [diff] [blame] | 135 | Open a file search dialog. Put results in a new output window. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 136 | |
| 137 | Replace... |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 138 | Open a search-and-replace dialog. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 139 | |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 140 | Go to Line |
| 141 | Move cursor to the line number requested and make that line visible. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 142 | |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 143 | Show Completions |
| 144 | Open a scrollable list allowing selection of keywords and attributes. See |
| 145 | Completions in the Tips sections below. |
| 146 | |
| 147 | Expand Word |
| 148 | Expand a prefix you have typed to match a full word in the same window; |
| 149 | repeat to get a different expansion. |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 150 | |
| 151 | Show call tip |
| 152 | After an unclosed parenthesis for a function, open a small window with |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 153 | function parameter hints. |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 154 | |
| 155 | Show surrounding parens |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 156 | Highlight the surrounding parenthesis. |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 157 | |
| 158 | Format menu (Editor window only) |
Terry Jan Reedy | f568494 | 2014-12-04 00:54:59 -0500 | [diff] [blame] | 159 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 160 | |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 161 | Indent Region |
| 162 | Shift selected lines right by the indent width (default 4 spaces). |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 163 | |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 164 | Dedent Region |
| 165 | Shift selected lines left by the indent width (default 4 spaces). |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 166 | |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 167 | Comment Out Region |
| 168 | Insert ## in front of selected lines. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 169 | |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 170 | Uncomment Region |
| 171 | Remove leading # or ## from selected lines. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 172 | |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 173 | Tabify Region |
| 174 | Turn *leading* stretches of spaces into tabs. (Note: We recommend using |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 175 | 4 space blocks to indent Python code.) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 176 | |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 177 | Untabify Region |
| 178 | Turn *all* tabs into the correct number of spaces. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 179 | |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 180 | Toggle Tabs |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 181 | Open a dialog to switch between indenting with spaces and tabs. |
| 182 | |
| 183 | New Indent Width |
| 184 | Open a dialog to change indent width. The accepted default by the Python |
| 185 | community is 4 spaces. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 186 | |
| 187 | Format Paragraph |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 188 | Reformat the current blank-line-delimited paragraph in comment block or |
| 189 | multiline string or selected line in a string. All lines in the |
| 190 | paragraph will be formatted to less than N columns, where N defaults to 72. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 191 | |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 192 | Strip trailing whitespace |
Terry Jan Reedy | ff70289 | 2017-09-15 13:05:28 -0400 | [diff] [blame] | 193 | Remove trailing space and other whitespace characters after the last |
| 194 | non-whitespace character of a line by applying str.rstrip to each line, |
| 195 | including lines within multiline strings. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 196 | |
| 197 | .. index:: |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 198 | single: Run script |
| 199 | |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 200 | Run menu (Editor window only) |
| 201 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 202 | |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 203 | Python Shell |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 204 | Open or wake up the Python Shell window. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 205 | |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 206 | Check Module |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 207 | Check the syntax of the module currently open in the Editor window. If the |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 208 | module has not been saved IDLE will either prompt the user to save or |
| 209 | autosave, as selected in the General tab of the Idle Settings dialog. If |
| 210 | there is a syntax error, the approximate location is indicated in the |
| 211 | Editor window. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 212 | |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 213 | Run Module |
| 214 | Do Check Module (above). If no error, restart the shell to clean the |
Terry Jan Reedy | 8b5a981 | 2015-09-24 01:39:30 -0400 | [diff] [blame] | 215 | environment, then execute the module. Output is displayed in the Shell |
| 216 | window. Note that output requires use of ``print`` or ``write``. |
| 217 | When execution is complete, the Shell retains focus and displays a prompt. |
| 218 | At this point, one may interactively explore the result of execution. |
| 219 | This is similar to executing a file with ``python -i file`` at a command |
| 220 | line. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 221 | |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 222 | Shell menu (Shell window only) |
| 223 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
Ned Deily | 2778d0d | 2012-10-20 13:25:34 -0700 | [diff] [blame] | 224 | |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 225 | View Last Restart |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 226 | Scroll the shell window to the last Shell restart. |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 227 | |
| 228 | Restart Shell |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 229 | Restart the shell to clean the environment. |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 230 | |
Terry Jan Reedy | 4b73676 | 2016-09-12 01:50:03 -0400 | [diff] [blame] | 231 | Interrupt Execution |
| 232 | Stop a running program. |
| 233 | |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 234 | Debug menu (Shell window only) |
| 235 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 236 | |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 237 | Go to File/Line |
| 238 | Look on the current line. with the cursor, and the line above for a filename |
| 239 | and line number. If found, open the file if not already open, and show the |
| 240 | line. Use this to view source lines referenced in an exception traceback |
| 241 | and lines found by Find in Files. Also available in the context menu of |
| 242 | the Shell window and Output windows. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 243 | |
| 244 | .. index:: |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 245 | single: debugger |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 246 | single: stack viewer |
| 247 | |
| 248 | Debugger (toggle) |
csabella | 9dc2b38 | 2017-04-29 18:28:36 -0400 | [diff] [blame] | 249 | When activated, code entered in the Shell or run from an Editor will run |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 250 | under the debugger. In the Editor, breakpoints can be set with the context |
| 251 | menu. This feature is still incomplete and somewhat experimental. |
| 252 | |
| 253 | Stack Viewer |
| 254 | Show the stack traceback of the last exception in a tree widget, with |
| 255 | access to locals and globals. |
| 256 | |
| 257 | Auto-open Stack Viewer |
| 258 | Toggle automatically opening the stack viewer on an unhandled exception. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 259 | |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 260 | Options menu (Shell and Editor) |
| 261 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 262 | |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 263 | Configure IDLE |
Terry Jan Reedy | 93f3542 | 2015-10-13 22:03:51 -0400 | [diff] [blame] | 264 | Open a configuration dialog and change preferences for the following: |
| 265 | fonts, indentation, keybindings, text color themes, startup windows and |
| 266 | size, additional help sources, and extensions (see below). On OS X, |
| 267 | open the configuration dialog by selecting Preferences in the application |
| 268 | menu. To use a new built-in color theme (IDLE Dark) with older IDLEs, |
| 269 | save it as a new custom theme. |
Ned Deily | 2778d0d | 2012-10-20 13:25:34 -0700 | [diff] [blame] | 270 | |
Terry Jan Reedy | 93f3542 | 2015-10-13 22:03:51 -0400 | [diff] [blame] | 271 | Non-default user settings are saved in a .idlerc directory in the user's |
| 272 | home directory. Problems caused by bad user configuration files are solved |
| 273 | by editing or deleting one or more of the files in .idlerc. |
Terry Jan Reedy | bb37b4c | 2014-12-04 01:26:04 -0500 | [diff] [blame] | 274 | |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 275 | Code Context (toggle)(Editor Window only) |
| 276 | Open a pane at the top of the edit window which shows the block context |
Terry Jan Reedy | af4b013 | 2018-06-10 15:48:41 -0400 | [diff] [blame] | 277 | of the code which has scrolled above the top of the window. Clicking a |
| 278 | line in this pane exposes that line at the top of the editor. |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 279 | |
Ned Deily | ccb416f | 2015-01-17 21:06:27 -0800 | [diff] [blame] | 280 | Window menu (Shell and Editor) |
| 281 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 282 | |
| 283 | Zoom Height |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 284 | Toggles the window between normal size and maximum height. The initial size |
| 285 | defaults to 40 lines by 80 chars unless changed on the General tab of the |
| 286 | Configure IDLE dialog. |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 287 | |
| 288 | The rest of this menu lists the names of all open windows; select one to bring |
| 289 | it to the foreground (deiconifying it if necessary). |
| 290 | |
| 291 | Help menu (Shell and Editor) |
| 292 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 293 | |
| 294 | About IDLE |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 295 | Display version, copyright, license, credits, and more. |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 296 | |
| 297 | IDLE Help |
Terry Jan Reedy | 1803263 | 2018-10-28 16:21:18 -0400 | [diff] [blame] | 298 | Display this IDLE document, detailing the menu options, basic editing and |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 299 | navigation, and other tips. |
| 300 | |
| 301 | Python Docs |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 302 | Access local Python documentation, if installed, or start a web browser |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 303 | and open docs.python.org showing the latest Python documentation. |
| 304 | |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 305 | Turtle Demo |
Andrés Delfino | 271818f | 2018-09-14 14:13:09 -0300 | [diff] [blame] | 306 | Run the turtledemo module with example Python code and turtle drawings. |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 307 | |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 308 | Additional help sources may be added here with the Configure IDLE dialog under |
Terry Jan Reedy | 1803263 | 2018-10-28 16:21:18 -0400 | [diff] [blame] | 309 | the General tab. See the "Help sources" subsection below for more |
| 310 | on Help menu choices. |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 311 | |
Terry Jan Reedy | f568494 | 2014-12-04 00:54:59 -0500 | [diff] [blame] | 312 | .. index:: |
| 313 | single: Cut |
| 314 | single: Copy |
| 315 | single: Paste |
| 316 | single: Set Breakpoint |
| 317 | single: Clear Breakpoint |
| 318 | single: breakpoints |
| 319 | |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 320 | Context Menus |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 321 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 322 | |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 323 | Open a context menu by right-clicking in a window (Control-click on OS X). |
| 324 | Context menus have the standard clipboard functions also on the Edit menu. |
Ned Deily | 2778d0d | 2012-10-20 13:25:34 -0700 | [diff] [blame] | 325 | |
Andrew Svetlov | d183767 | 2012-11-01 22:41:19 +0200 | [diff] [blame] | 326 | Cut |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 327 | Copy selection into the system-wide clipboard; then delete the selection. |
Andrew Svetlov | d183767 | 2012-11-01 22:41:19 +0200 | [diff] [blame] | 328 | |
| 329 | Copy |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 330 | Copy selection into the system-wide clipboard. |
Andrew Svetlov | d183767 | 2012-11-01 22:41:19 +0200 | [diff] [blame] | 331 | |
| 332 | Paste |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 333 | Insert contents of the system-wide clipboard into the current window. |
| 334 | |
| 335 | Editor windows also have breakpoint functions. Lines with a breakpoint set are |
| 336 | specially marked. Breakpoints only have an effect when running under the |
| 337 | debugger. Breakpoints for a file are saved in the user's .idlerc directory. |
Andrew Svetlov | d183767 | 2012-11-01 22:41:19 +0200 | [diff] [blame] | 338 | |
Ned Deily | 2778d0d | 2012-10-20 13:25:34 -0700 | [diff] [blame] | 339 | Set Breakpoint |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 340 | Set a breakpoint on the current line. |
Ned Deily | 2778d0d | 2012-10-20 13:25:34 -0700 | [diff] [blame] | 341 | |
| 342 | Clear Breakpoint |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 343 | Clear the breakpoint on that line. |
Ned Deily | 2778d0d | 2012-10-20 13:25:34 -0700 | [diff] [blame] | 344 | |
Terry Jan Reedy | 68d6dc0 | 2018-10-28 12:44:44 -0400 | [diff] [blame] | 345 | Shell and Output windows also have the following. |
Andrew Svetlov | d183767 | 2012-11-01 22:41:19 +0200 | [diff] [blame] | 346 | |
Ned Deily | 2778d0d | 2012-10-20 13:25:34 -0700 | [diff] [blame] | 347 | Go to file/line |
| 348 | Same as in Debug menu. |
| 349 | |
Terry Jan Reedy | 68d6dc0 | 2018-10-28 12:44:44 -0400 | [diff] [blame] | 350 | The Shell window also has an output squeezing facility explained in the |
| 351 | the *Python Shell window* subsection below. |
| 352 | |
| 353 | Squeeze |
| 354 | If the cursor is over an output line, squeeze all the output between |
| 355 | the code above and the prompt below down to a 'Squeezed text' label. |
| 356 | |
Ned Deily | 2778d0d | 2012-10-20 13:25:34 -0700 | [diff] [blame] | 357 | |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 358 | Editing and navigation |
| 359 | ---------------------- |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 360 | |
Terry Jan Reedy | ea9c8bd | 2018-10-28 20:42:18 -0400 | [diff] [blame] | 361 | Editor windows |
| 362 | ^^^^^^^^^^^^^^ |
| 363 | |
| 364 | IDLE may open editor windows when it starts, depending on settings |
| 365 | and how you start IDLE. Thereafter, use the File menu. There can be only |
| 366 | one open editor window for a given file. |
| 367 | |
| 368 | The title bar contains the name of the file, the full path, and the version |
| 369 | of Python and IDLE running the window. The status bar contains the line |
| 370 | number ('Ln') and column number ('Col'). Line numbers start with 1; |
| 371 | column numbers with 0. |
| 372 | |
| 373 | IDLE assumes that files with a known .py* extension contain Python code |
| 374 | and that other files do not. Run Python code with the Run menu. |
| 375 | |
| 376 | Key bindings |
| 377 | ^^^^^^^^^^^^ |
| 378 | |
Serhiy Storchaka | 0424eaf | 2015-09-12 17:45:25 +0300 | [diff] [blame] | 379 | In this section, 'C' refers to the :kbd:`Control` key on Windows and Unix and |
| 380 | the :kbd:`Command` key on Mac OSX. |
Terry Jan Reedy | f568494 | 2014-12-04 00:54:59 -0500 | [diff] [blame] | 381 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 382 | * :kbd:`Backspace` deletes to the left; :kbd:`Del` deletes to the right |
| 383 | |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 384 | * :kbd:`C-Backspace` delete word left; :kbd:`C-Del` delete word to the right |
| 385 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 386 | * Arrow keys and :kbd:`Page Up`/:kbd:`Page Down` to move around |
| 387 | |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 388 | * :kbd:`C-LeftArrow` and :kbd:`C-RightArrow` moves by words |
| 389 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 390 | * :kbd:`Home`/:kbd:`End` go to begin/end of line |
| 391 | |
| 392 | * :kbd:`C-Home`/:kbd:`C-End` go to begin/end of file |
| 393 | |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 394 | * Some useful Emacs bindings are inherited from Tcl/Tk: |
| 395 | |
| 396 | * :kbd:`C-a` beginning of line |
| 397 | |
| 398 | * :kbd:`C-e` end of line |
| 399 | |
| 400 | * :kbd:`C-k` kill line (but doesn't put it in clipboard) |
| 401 | |
| 402 | * :kbd:`C-l` center window around the insertion point |
| 403 | |
csabella | 9dc2b38 | 2017-04-29 18:28:36 -0400 | [diff] [blame] | 404 | * :kbd:`C-b` go backward one character without deleting (usually you can |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 405 | also use the cursor key for this) |
| 406 | |
| 407 | * :kbd:`C-f` go forward one character without deleting (usually you can |
| 408 | also use the cursor key for this) |
| 409 | |
| 410 | * :kbd:`C-p` go up one line (usually you can also use the cursor key for |
| 411 | this) |
| 412 | |
| 413 | * :kbd:`C-d` delete next character |
| 414 | |
| 415 | Standard keybindings (like :kbd:`C-c` to copy and :kbd:`C-v` to paste) |
| 416 | may work. Keybindings are selected in the Configure IDLE dialog. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 417 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 418 | Automatic indentation |
| 419 | ^^^^^^^^^^^^^^^^^^^^^ |
| 420 | |
| 421 | After a block-opening statement, the next line is indented by 4 spaces (in the |
| 422 | Python Shell window by one tab). After certain keywords (break, return etc.) |
| 423 | the next line is dedented. In leading indentation, :kbd:`Backspace` deletes up |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 424 | to 4 spaces if they are there. :kbd:`Tab` inserts spaces (in the Python |
csabella | 9dc2b38 | 2017-04-29 18:28:36 -0400 | [diff] [blame] | 425 | Shell window one tab), number depends on Indent width. Currently, tabs |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 426 | are restricted to four spaces due to Tcl/Tk limitations. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 427 | |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 428 | See also the indent/dedent region commands in the edit menu. |
| 429 | |
| 430 | Completions |
| 431 | ^^^^^^^^^^^ |
| 432 | |
| 433 | Completions are supplied for functions, classes, and attributes of classes, |
| 434 | both built-in and user-defined. Completions are also provided for |
| 435 | filenames. |
| 436 | |
| 437 | The AutoCompleteWindow (ACW) will open after a predefined delay (default is |
| 438 | two seconds) after a '.' or (in a string) an os.sep is typed. If after one |
| 439 | of those characters (plus zero or more other characters) a tab is typed |
| 440 | the ACW will open immediately if a possible continuation is found. |
| 441 | |
| 442 | If there is only one possible completion for the characters entered, a |
| 443 | :kbd:`Tab` will supply that completion without opening the ACW. |
| 444 | |
| 445 | 'Show Completions' will force open a completions window, by default the |
| 446 | :kbd:`C-space` will open a completions window. In an empty |
| 447 | string, this will contain the files in the current directory. On a |
| 448 | blank line, it will contain the built-in and user-defined functions and |
csabella | 9dc2b38 | 2017-04-29 18:28:36 -0400 | [diff] [blame] | 449 | classes in the current namespaces, plus any modules imported. If some |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 450 | characters have been entered, the ACW will attempt to be more specific. |
| 451 | |
| 452 | If a string of characters is typed, the ACW selection will jump to the |
| 453 | entry most closely matching those characters. Entering a :kbd:`tab` will |
| 454 | cause the longest non-ambiguous match to be entered in the Editor window or |
| 455 | Shell. Two :kbd:`tab` in a row will supply the current ACW selection, as |
| 456 | will return or a double click. Cursor keys, Page Up/Down, mouse selection, |
| 457 | and the scroll wheel all operate on the ACW. |
| 458 | |
| 459 | "Hidden" attributes can be accessed by typing the beginning of hidden |
| 460 | name after a '.', e.g. '_'. This allows access to modules with |
| 461 | ``__all__`` set, or to class-private attributes. |
| 462 | |
| 463 | Completions and the 'Expand Word' facility can save a lot of typing! |
| 464 | |
| 465 | Completions are currently limited to those in the namespaces. Names in |
| 466 | an Editor window which are not via ``__main__`` and :data:`sys.modules` will |
| 467 | not be found. Run the module once with your imports to correct this situation. |
| 468 | Note that IDLE itself places quite a few modules in sys.modules, so |
| 469 | much can be found by default, e.g. the re module. |
| 470 | |
| 471 | If you don't like the ACW popping up unbidden, simply make the delay |
Terry Jan Reedy | 37f8135 | 2015-09-29 01:55:57 -0400 | [diff] [blame] | 472 | longer or disable the extension. |
| 473 | |
| 474 | Calltips |
| 475 | ^^^^^^^^ |
| 476 | |
Alex Gaynor | 1cf2a80 | 2017-02-28 22:26:56 -0500 | [diff] [blame] | 477 | A calltip is shown when one types :kbd:`(` after the name of an *accessible* |
Terry Jan Reedy | 37f8135 | 2015-09-29 01:55:57 -0400 | [diff] [blame] | 478 | function. A name expression may include dots and subscripts. A calltip |
| 479 | remains until it is clicked, the cursor is moved out of the argument area, |
| 480 | or :kbd:`)` is typed. When the cursor is in the argument part of a definition, |
| 481 | the menu or shortcut display a calltip. |
| 482 | |
| 483 | A calltip consists of the function signature and the first line of the |
| 484 | docstring. For builtins without an accessible signature, the calltip |
| 485 | consists of all lines up the fifth line or the first blank line. These |
| 486 | details may change. |
| 487 | |
| 488 | The set of *accessible* functions depends on what modules have been imported |
| 489 | into the user process, including those imported by Idle itself, |
| 490 | and what definitions have been run, all since the last restart. |
| 491 | |
| 492 | For example, restart the Shell and enter ``itertools.count(``. A calltip |
| 493 | appears because Idle imports itertools into the user process for its own use. |
| 494 | (This could change.) Enter ``turtle.write(`` and nothing appears. Idle does |
| 495 | not import turtle. The menu or shortcut do nothing either. Enter |
| 496 | ``import turtle`` and then ``turtle.write(`` will work. |
| 497 | |
| 498 | In an editor, import statements have no effect until one runs the file. One |
| 499 | might want to run a file after writing the import statements at the top, |
| 500 | or immediately run an existing file before editing. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 501 | |
| 502 | Python Shell window |
| 503 | ^^^^^^^^^^^^^^^^^^^ |
| 504 | |
Terry Jan Reedy | 75d9d59 | 2018-11-06 12:37:36 -0500 | [diff] [blame] | 505 | With IDLE's Shell, one enters, edits, and recalls complete statements. |
| 506 | Most consoles and terminals only work with a single physical line at a time. |
| 507 | |
| 508 | When one pastes code into Shell, it is not compiled and possibly executed |
| 509 | until one hits :kbd:`Return`. One may edit pasted code first. |
| 510 | If one pastes more that one statement into Shell, the result will be a |
| 511 | :exc:`SyntaxError` when multiple statements are compiled as if they were one. |
| 512 | |
| 513 | The editing features described in previous subsections work when entering |
| 514 | code interactively. IDLE's Shell window also responds to the following keys. |
Terry Jan Reedy | 68d6dc0 | 2018-10-28 12:44:44 -0400 | [diff] [blame] | 515 | |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 516 | * :kbd:`C-c` interrupts executing command |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 517 | |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 518 | * :kbd:`C-d` sends end-of-file; closes window if typed at a ``>>>`` prompt |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 519 | |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 520 | * :kbd:`Alt-/` (Expand word) is also useful to reduce typing |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 521 | |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 522 | Command history |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 523 | |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 524 | * :kbd:`Alt-p` retrieves previous command matching what you have typed. On |
| 525 | OS X use :kbd:`C-p`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 526 | |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 527 | * :kbd:`Alt-n` retrieves next. On OS X use :kbd:`C-n`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 528 | |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 529 | * :kbd:`Return` while on any previous command retrieves that command |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 530 | |
Terry Jan Reedy | f660ce2 | 2015-09-24 23:13:49 -0400 | [diff] [blame] | 531 | Text colors |
| 532 | ^^^^^^^^^^^ |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 533 | |
Terry Jan Reedy | f660ce2 | 2015-09-24 23:13:49 -0400 | [diff] [blame] | 534 | Idle defaults to black on white text, but colors text with special meanings. |
| 535 | For the shell, these are shell output, shell error, user output, and |
| 536 | user error. For Python code, at the shell prompt or in an editor, these are |
| 537 | keywords, builtin class and function names, names following ``class`` and |
| 538 | ``def``, strings, and comments. For any text window, these are the cursor (when |
| 539 | present), found text (when possible), and selected text. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 540 | |
Terry Jan Reedy | f660ce2 | 2015-09-24 23:13:49 -0400 | [diff] [blame] | 541 | Text coloring is done in the background, so uncolorized text is occasionally |
| 542 | visible. To change the color scheme, use the Configure IDLE dialog |
| 543 | Highlighting tab. The marking of debugger breakpoint lines in the editor and |
| 544 | text in popups and dialogs is not user-configurable. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 545 | |
| 546 | |
Terry Jan Reedy | 0053c47 | 2015-09-24 03:09:43 -0400 | [diff] [blame] | 547 | Startup and code execution |
| 548 | -------------------------- |
Benjamin Peterson | f07d002 | 2009-03-21 17:31:58 +0000 | [diff] [blame] | 549 | |
| 550 | Upon startup with the ``-s`` option, IDLE will execute the file referenced by |
| 551 | the environment variables :envvar:`IDLESTARTUP` or :envvar:`PYTHONSTARTUP`. |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 552 | IDLE first checks for ``IDLESTARTUP``; if ``IDLESTARTUP`` is present the file |
| 553 | referenced is run. If ``IDLESTARTUP`` is not present, IDLE checks for |
Benjamin Peterson | f07d002 | 2009-03-21 17:31:58 +0000 | [diff] [blame] | 554 | ``PYTHONSTARTUP``. Files referenced by these environment variables are |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 555 | convenient places to store functions that are used frequently from the IDLE |
Benjamin Peterson | f07d002 | 2009-03-21 17:31:58 +0000 | [diff] [blame] | 556 | shell, or for executing import statements to import common modules. |
| 557 | |
| 558 | In addition, ``Tk`` also loads a startup file if it is present. Note that the |
| 559 | Tk file is loaded unconditionally. This additional file is ``.Idle.py`` and is |
| 560 | looked for in the user's home directory. Statements in this file will be |
Terry Jan Reedy | 3ab745e | 2014-12-05 02:43:07 -0500 | [diff] [blame] | 561 | executed in the Tk namespace, so this file is not useful for importing |
| 562 | functions to be used from IDLE's Python shell. |
Benjamin Peterson | f07d002 | 2009-03-21 17:31:58 +0000 | [diff] [blame] | 563 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 564 | Command line usage |
| 565 | ^^^^^^^^^^^^^^^^^^ |
| 566 | |
Martin Panter | 1050d2d | 2016-07-26 11:18:21 +0200 | [diff] [blame] | 567 | .. code-block:: none |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 568 | |
Terry Jan Reedy | 968e285 | 2015-09-23 03:52:23 -0400 | [diff] [blame] | 569 | idle.py [-c command] [-d] [-e] [-h] [-i] [-r file] [-s] [-t title] [-] [arg] ... |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 570 | |
Terry Jan Reedy | 968e285 | 2015-09-23 03:52:23 -0400 | [diff] [blame] | 571 | -c command run command in the shell window |
| 572 | -d enable debugger and open shell window |
| 573 | -e open editor window |
Terry Jan Reedy | 3399e1e | 2016-08-30 16:58:01 -0400 | [diff] [blame] | 574 | -h print help message with legal combinations and exit |
Terry Jan Reedy | 968e285 | 2015-09-23 03:52:23 -0400 | [diff] [blame] | 575 | -i open shell window |
| 576 | -r file run file in shell window |
| 577 | -s run $IDLESTARTUP or $PYTHONSTARTUP first, in shell window |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 578 | -t title set title of shell window |
Terry Jan Reedy | 968e285 | 2015-09-23 03:52:23 -0400 | [diff] [blame] | 579 | - run stdin in shell (- must be last option before args) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 580 | |
| 581 | If there are arguments: |
| 582 | |
Terry Jan Reedy | 968e285 | 2015-09-23 03:52:23 -0400 | [diff] [blame] | 583 | * If ``-``, ``-c``, or ``r`` is used, all arguments are placed in |
| 584 | ``sys.argv[1:...]`` and ``sys.argv[0]`` is set to ``''``, ``'-c'``, |
| 585 | or ``'-r'``. No editor window is opened, even if that is the default |
| 586 | set in the Options dialog. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 587 | |
Terry Jan Reedy | 968e285 | 2015-09-23 03:52:23 -0400 | [diff] [blame] | 588 | * Otherwise, arguments are files opened for editing and |
| 589 | ``sys.argv`` reflects the arguments passed to IDLE itself. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 590 | |
terryjreedy | 188aedf | 2017-06-13 21:32:16 -0400 | [diff] [blame] | 591 | Startup failure |
| 592 | ^^^^^^^^^^^^^^^ |
| 593 | |
| 594 | IDLE uses a socket to communicate between the IDLE GUI process and the user |
| 595 | code execution process. A connection must be established whenever the Shell |
| 596 | starts or restarts. (The latter is indicated by a divider line that says |
| 597 | 'RESTART'). If the user process fails to connect to the GUI process, it |
| 598 | displays a ``Tk`` error box with a 'cannot connect' message that directs the |
| 599 | user here. It then exits. |
| 600 | |
| 601 | A common cause of failure is a user-written file with the same name as a |
| 602 | standard library module, such as *random.py* and *tkinter.py*. When such a |
| 603 | file is located in the same directory as a file that is about to be run, |
| 604 | IDLE cannot import the stdlib file. The current fix is to rename the |
| 605 | user file. |
| 606 | |
| 607 | Though less common than in the past, an antivirus or firewall program may |
| 608 | stop the connection. If the program cannot be taught to allow the |
| 609 | connection, then it must be turned off for IDLE to work. It is safe to |
| 610 | allow this internal connection because no data is visible on external |
| 611 | ports. A similar problem is a network mis-configuration that blocks |
| 612 | connections. |
| 613 | |
| 614 | Python installation issues occasionally stop IDLE: multiple versions can |
| 615 | clash, or a single installation might need admin access. If one undo the |
| 616 | clash, or cannot or does not want to run as admin, it might be easiest to |
| 617 | completely remove Python and start over. |
| 618 | |
| 619 | A zombie pythonw.exe process could be a problem. On Windows, use Task |
| 620 | Manager to detect and stop one. Sometimes a restart initiated by a program |
| 621 | crash or Keyboard Interrupt (control-C) may fail to connect. Dismissing |
| 622 | the error box or Restart Shell on the Shell menu may fix a temporary problem. |
| 623 | |
| 624 | When IDLE first starts, it attempts to read user configuration files in |
| 625 | ~/.idlerc/ (~ is one's home directory). If there is a problem, an error |
| 626 | message should be displayed. Leaving aside random disk glitches, this can |
| 627 | be prevented by never editing the files by hand, using the configuration |
| 628 | dialog, under Options, instead Options. Once it happens, the solution may |
| 629 | be to delete one or more of the configuration files. |
| 630 | |
| 631 | If IDLE quits with no message, and it was not started from a console, try |
| 632 | starting from a console (``python -m idlelib)`` and see if a message appears. |
| 633 | |
Terry Jan Reedy | 5e79090 | 2018-11-05 21:30:32 -0500 | [diff] [blame] | 634 | Running user code |
| 635 | ^^^^^^^^^^^^^^^^^ |
Terry Jan Reedy | 0053c47 | 2015-09-24 03:09:43 -0400 | [diff] [blame] | 636 | |
Terry Jan Reedy | 98758bc | 2017-09-12 09:05:16 -0400 | [diff] [blame] | 637 | With rare exceptions, the result of executing Python code with IDLE is |
Terry Jan Reedy | 5e79090 | 2018-11-05 21:30:32 -0500 | [diff] [blame] | 638 | intended to be the same as executing the same code by the default method, |
| 639 | directly with Python in a text-mode system console or terminal window. |
Terry Jan Reedy | 98758bc | 2017-09-12 09:05:16 -0400 | [diff] [blame] | 640 | However, the different interface and operation occasionally affect |
Terry Jan Reedy | 5e79090 | 2018-11-05 21:30:32 -0500 | [diff] [blame] | 641 | visible results. For instance, ``sys.modules`` starts with more entries, |
| 642 | and ``threading.activeCount()`` returns 2 instead of 1. |
Terry Jan Reedy | 0053c47 | 2015-09-24 03:09:43 -0400 | [diff] [blame] | 643 | |
Terry Jan Reedy | 5e79090 | 2018-11-05 21:30:32 -0500 | [diff] [blame] | 644 | By default, IDLE runs user code in a separate OS process rather than in |
| 645 | the user interface process that runs the shell and editor. In the execution |
| 646 | process, it replaces ``sys.stdin``, ``sys.stdout``, and ``sys.stderr`` |
| 647 | with objects that get input from and send output to the Shell window. |
| 648 | The original values stored in ``sys.__stdin__``, ``sys.__stdout__``, and |
| 649 | ``sys.__stderr__`` are not touched, but may be ``None``. |
| 650 | |
Terry Jan Reedy | 98758bc | 2017-09-12 09:05:16 -0400 | [diff] [blame] | 651 | When Shell has the focus, it controls the keyboard and screen. This is |
| 652 | normally transparent, but functions that directly access the keyboard |
Terry Jan Reedy | 5e79090 | 2018-11-05 21:30:32 -0500 | [diff] [blame] | 653 | and screen will not work. These include system-specific functions that |
| 654 | determine whether a key has been pressed and if so, which. |
Terry Jan Reedy | 0053c47 | 2015-09-24 03:09:43 -0400 | [diff] [blame] | 655 | |
Terry Jan Reedy | 5e79090 | 2018-11-05 21:30:32 -0500 | [diff] [blame] | 656 | IDLE's standard stream replacements are not inherited by subprocesses |
| 657 | created in the execution process, whether directly by user code or by modules |
| 658 | such as multiprocessing. If such subprocess use ``input`` from sys.stdin |
| 659 | or ``print`` or ``write`` to sys.stdout or sys.stderr, |
| 660 | IDLE should be started in a command line window. The secondary subprocess |
| 661 | will then be attached to that window for input and output. |
| 662 | |
| 663 | If ``sys`` is reset by user code, such as with ``importlib.reload(sys)``, |
| 664 | IDLE's changes are lost and input from the keyboard and output to the screen |
| 665 | will not work correctly. |
Terry Jan Reedy | 0053c47 | 2015-09-24 03:09:43 -0400 | [diff] [blame] | 666 | |
Terry Jan Reedy | 75d9d59 | 2018-11-06 12:37:36 -0500 | [diff] [blame] | 667 | User output in Shell |
| 668 | ^^^^^^^^^^^^^^^^^^^^ |
| 669 | |
| 670 | When a program outputs text, the result is determined by the |
| 671 | corresponding output device. When IDLE executes user code, ``sys.stdout`` |
| 672 | and ``sys.stderr`` are connected to the display area of IDLE's Shell. Some of |
| 673 | its features are inherited from the underlying Tk Text widget. Others |
Terry Jan Reedy | 76cd0c3 | 2018-11-06 23:55:06 -0500 | [diff] [blame] | 674 | are programmed additions. Where it matters, Shell is designed for development |
| 675 | rather than production runs. |
| 676 | |
| 677 | For instance, Shell never throws away output. A program that sends unlimited |
| 678 | output to Shell will eventually fill memory, resulting in a memory error. |
| 679 | In contrast, some system text windows only keep the last n lines of output. |
| 680 | A Windows console, for instance, keeps a user-settable 1 to 9999 lines, |
| 681 | with 300 the default. |
Terry Jan Reedy | 75d9d59 | 2018-11-06 12:37:36 -0500 | [diff] [blame] | 682 | |
| 683 | Text widgets display a subset of Unicode, the Basic Multilingual Plane (BMP). |
| 684 | Which characters get a proper glyph instead of a replacement box depends on |
| 685 | the operating system and installed fonts. Newline characters cause following |
Terry Jan Reedy | 76cd0c3 | 2018-11-06 23:55:06 -0500 | [diff] [blame] | 686 | text to appear on a new line, but other control characters are either |
| 687 | replaced with a box or deleted. However, ``repr()``, which is used for |
| 688 | interactive echo of expression values, replaces control characters, |
| 689 | some BMP codepoints, and all non-BMP characters with escape codes |
| 690 | before they are output. |
Terry Jan Reedy | 75d9d59 | 2018-11-06 12:37:36 -0500 | [diff] [blame] | 691 | |
| 692 | Normal and error output are generally kept separate (on separate lines) |
| 693 | from code input and each other. They each get different highlight colors. |
| 694 | |
| 695 | For SyntaxError tracebacks, the normal '^' marking where the error was |
| 696 | detected is replaced by coloring the text with an error highlight. |
| 697 | When code run from a file causes other exceptions, one may right click |
| 698 | on a traceback line to jump to the corresponding line in an IDLE editor. |
| 699 | The file will be opened if necessary. |
| 700 | |
| 701 | Shell has a special facility for squeezing output lines down to a |
| 702 | 'Squeezed text' label. This is done automatically |
| 703 | for output over N lines (N = 50 by default). |
| 704 | N can be changed in the PyShell section of the General |
| 705 | page of the Settings dialog. Output with fewer lines can be squeezed by |
| 706 | right clicking on the output. This can be useful lines long enough to slow |
| 707 | down scrolling. |
| 708 | |
| 709 | Squeezed output is expanded in place by double-clicking the label. |
| 710 | It can also be sent to the clipboard or a separate view window by |
| 711 | right-clicking the label. |
| 712 | |
Terry Jan Reedy | 98758bc | 2017-09-12 09:05:16 -0400 | [diff] [blame] | 713 | Developing tkinter applications |
| 714 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 715 | |
| 716 | IDLE is intentionally different from standard Python in order to |
| 717 | facilitate development of tkinter programs. Enter ``import tkinter as tk; |
| 718 | root = tk.Tk()`` in standard Python and nothing appears. Enter the same |
| 719 | in IDLE and a tk window appears. In standard Python, one must also enter |
| 720 | ``root.update()`` to see the window. IDLE does the equivalent in the |
| 721 | background, about 20 times a second, which is about every 50 milleseconds. |
| 722 | Next enter ``b = tk.Button(root, text='button'); b.pack()``. Again, |
| 723 | nothing visibly changes in standard Python until one enters ``root.update()``. |
| 724 | |
| 725 | Most tkinter programs run ``root.mainloop()``, which usually does not |
| 726 | return until the tk app is destroyed. If the program is run with |
| 727 | ``python -i`` or from an IDLE editor, a ``>>>`` shell prompt does not |
| 728 | appear until ``mainloop()`` returns, at which time there is nothing left |
| 729 | to interact with. |
| 730 | |
| 731 | When running a tkinter program from an IDLE editor, one can comment out |
| 732 | the mainloop call. One then gets a shell prompt immediately and can |
| 733 | interact with the live application. One just has to remember to |
| 734 | re-enable the mainloop call when running in standard Python. |
| 735 | |
Terry Jan Reedy | f568494 | 2014-12-04 00:54:59 -0500 | [diff] [blame] | 736 | Running without a subprocess |
| 737 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 738 | |
Terry Jan Reedy | 0053c47 | 2015-09-24 03:09:43 -0400 | [diff] [blame] | 739 | By default, IDLE executes user code in a separate subprocess via a socket, |
Terry Jan Reedy | 6e10ec5 | 2015-09-23 20:00:33 -0400 | [diff] [blame] | 740 | which uses the internal loopback interface. This connection is not |
| 741 | externally visible and no data is sent to or received from the Internet. |
| 742 | If firewall software complains anyway, you can ignore it. |
| 743 | |
| 744 | If the attempt to make the socket connection fails, Idle will notify you. |
| 745 | Such failures are sometimes transient, but if persistent, the problem |
csabella | 9dc2b38 | 2017-04-29 18:28:36 -0400 | [diff] [blame] | 746 | may be either a firewall blocking the connection or misconfiguration of |
Terry Jan Reedy | 6e10ec5 | 2015-09-23 20:00:33 -0400 | [diff] [blame] | 747 | a particular system. Until the problem is fixed, one can run Idle with |
| 748 | the -n command line switch. |
| 749 | |
Terry Jan Reedy | f568494 | 2014-12-04 00:54:59 -0500 | [diff] [blame] | 750 | If IDLE is started with the -n command line switch it will run in a |
| 751 | single process and will not create the subprocess which runs the RPC |
| 752 | Python execution server. This can be useful if Python cannot create |
| 753 | the subprocess or the RPC socket interface on your platform. However, |
| 754 | in this mode user code is not isolated from IDLE itself. Also, the |
| 755 | environment is not restarted when Run/Run Module (F5) is selected. If |
| 756 | your code has been modified, you must reload() the affected modules and |
| 757 | re-import any specific items (e.g. from foo import baz) if the changes |
| 758 | are to take effect. For these reasons, it is preferable to run IDLE |
| 759 | with the default subprocess if at all possible. |
| 760 | |
| 761 | .. deprecated:: 3.4 |
| 762 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 763 | |
Terry Jan Reedy | bb37b4c | 2014-12-04 01:26:04 -0500 | [diff] [blame] | 764 | Help and preferences |
| 765 | -------------------- |
| 766 | |
Terry Jan Reedy | 1803263 | 2018-10-28 16:21:18 -0400 | [diff] [blame] | 767 | Help sources |
| 768 | ^^^^^^^^^^^^ |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 769 | |
Terry Jan Reedy | 1803263 | 2018-10-28 16:21:18 -0400 | [diff] [blame] | 770 | Help menu entry "IDLE Help" displays a formatted html version of the |
| 771 | IDLE chapter of the Library Reference. The result, in a read-only |
| 772 | tkinter text window, is close to what one sees in a web browser. |
| 773 | Navigate through the text with a mousewheel, |
| 774 | the scrollbar, or up and down arrow keys held down. |
| 775 | Or click the TOC (Table of Contents) button and select a section |
| 776 | header in the opened box. |
| 777 | |
| 778 | Help menu entry "Python Docs" opens the extensive sources of help, |
| 779 | including tutorials, available at docs.python.org/x.y, where 'x.y' |
| 780 | is the currently running Python version. If your system |
| 781 | has an off-line copy of the docs (this may be an installation option), |
| 782 | that will be opened instead. |
| 783 | |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 784 | Selected URLs can be added or removed from the help menu at any time using the |
Terry Jan Reedy | 1803263 | 2018-10-28 16:21:18 -0400 | [diff] [blame] | 785 | General tab of the Configure IDLE dialog . |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 786 | |
Terry Jan Reedy | bb37b4c | 2014-12-04 01:26:04 -0500 | [diff] [blame] | 787 | Setting preferences |
| 788 | ^^^^^^^^^^^^^^^^^^^ |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 789 | |
| 790 | The font preferences, highlighting, keys, and general preferences can be |
Terry Jan Reedy | bb37b4c | 2014-12-04 01:26:04 -0500 | [diff] [blame] | 791 | changed via Configure IDLE on the Option menu. Keys can be user defined; |
csabella | 9dc2b38 | 2017-04-29 18:28:36 -0400 | [diff] [blame] | 792 | IDLE ships with four built-in key sets. In addition, a user can create a |
Terry Jan Reedy | bb37b4c | 2014-12-04 01:26:04 -0500 | [diff] [blame] | 793 | custom key set in the Configure IDLE dialog under the keys tab. |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 794 | |
| 795 | Extensions |
Terry Jan Reedy | bb37b4c | 2014-12-04 01:26:04 -0500 | [diff] [blame] | 796 | ^^^^^^^^^^ |
Andrew Svetlov | 1bd7f02 | 2013-01-14 19:27:36 +0200 | [diff] [blame] | 797 | |
csabella | 9dc2b38 | 2017-04-29 18:28:36 -0400 | [diff] [blame] | 798 | IDLE contains an extension facility. Preferences for extensions can be |
Terry Jan Reedy | adb4cd2 | 2017-09-12 07:45:15 -0400 | [diff] [blame] | 799 | changed with the Extensions tab of the preferences dialog. See the |
| 800 | beginning of config-extensions.def in the idlelib directory for further |
| 801 | information. The only current default extension is zzdummy, an example |
| 802 | also used for testing. |