blob: 5f28a99e21c8e0ffa6dc3aac50b1e8b85ee54385 [file] [log] [blame]
Georg Brandl8ec7f652007-08-15 14:28:01 +00001.. _idle:
2
Georg Brandlb19be572007-12-29 10:57:00 +00003IDLE
Georg Brandl8ec7f652007-08-15 14:28:01 +00004====
5
6.. moduleauthor:: Guido van Rossum <guido@Python.org>
7
Georg Brandl8ec7f652007-08-15 14:28:01 +00008.. index::
Georg Brandlb19be572007-12-29 10:57:00 +00009 single: IDLE
Georg Brandl8ec7f652007-08-15 14:28:01 +000010 single: Python Editor
11 single: Integrated Development Environment
12
Georg Brandlc21cd7e2008-05-16 17:37:53 +000013IDLE is the Python IDE built with the :mod:`tkinter` GUI toolkit.
Georg Brandl8ec7f652007-08-15 14:28:01 +000014
15IDLE has the following features:
16
Georg Brandlc21cd7e2008-05-16 17:37:53 +000017* coded in 100% pure Python, using the :mod:`tkinter` GUI toolkit
Georg Brandl8ec7f652007-08-15 14:28:01 +000018
Georg Brandl9af94982008-09-13 17:41:16 +000019* cross-platform: works on Windows and Unix
Georg Brandl8ec7f652007-08-15 14:28:01 +000020
21* multi-window text editor with multiple undo, Python colorizing and many other
22 features, e.g. smart indent and call tips
23
24* Python shell window (a.k.a. interactive interpreter)
25
26* debugger (not complete, but you can set breakpoints, view and step)
27
28
29Menus
30-----
31
32
33File menu
34^^^^^^^^^
35
36New window
37 create a new editing window
38
39Open...
40 open an existing file
41
42Open module...
43 open an existing module (searches sys.path)
44
45Class browser
46 show classes and methods in current file
47
48Path browser
49 show sys.path directories, modules, classes and methods
50
51.. index::
52 single: Class browser
53 single: Path browser
54
55Save
56 save current window to the associated file (unsaved windows have a \* before and
57 after the window title)
58
59Save As...
60 save current window to new file, which becomes the associated file
61
62Save Copy As...
63 save current window to different file without changing the associated file
64
65Close
66 close current window (asks to save if unsaved)
67
68Exit
69 close all windows and quit IDLE (asks to save if unsaved)
70
71
72Edit menu
73^^^^^^^^^
74
75Undo
76 Undo last change to current window (max 1000 changes)
77
78Redo
79 Redo last undone change to current window
80
81Cut
82 Copy selection into system-wide clipboard; then delete selection
83
84Copy
85 Copy selection into system-wide clipboard
86
87Paste
88 Insert system-wide clipboard into window
89
90Select All
91 Select the entire contents of the edit buffer
92
93Find...
94 Open a search dialog box with many options
95
96Find again
97 Repeat last search
98
99Find selection
100 Search for the string in the selection
101
102Find in Files...
103 Open a search dialog box for searching files
104
105Replace...
106 Open a search-and-replace dialog box
107
108Go to line
109 Ask for a line number and show that line
110
111Indent region
112 Shift selected lines right 4 spaces
113
114Dedent region
115 Shift selected lines left 4 spaces
116
117Comment out region
118 Insert ## in front of selected lines
119
120Uncomment region
121 Remove leading # or ## from selected lines
122
123Tabify region
124 Turns *leading* stretches of spaces into tabs
125
126Untabify region
127 Turn *all* tabs into the right number of spaces
128
129Expand word
130 Expand the word you have typed to match another word in the same buffer; repeat
131 to get a different expansion
132
133Format Paragraph
134 Reformat the current blank-line-separated paragraph
135
136Import module
137 Import or reload the current module
138
139Run script
140 Execute the current file in the __main__ namespace
141
142.. index::
143 single: Import module
144 single: Run script
145
146
147Windows menu
148^^^^^^^^^^^^
149
150Zoom Height
151 toggles the window between normal size (24x80) and maximum height.
152
153The rest of this menu lists the names of all open windows; select one to bring
154it to the foreground (deiconifying it if necessary).
155
156
Ned Deilyc859bd22012-10-20 13:23:25 -0700157Debug menu
158^^^^^^^^^^
159
160* in the Python Shell window only
Georg Brandl8ec7f652007-08-15 14:28:01 +0000161
162Go to file/line
Ned Deilyc859bd22012-10-20 13:23:25 -0700163 Look around the insert point for a filename and line number, open the file,
164 and show the line. Useful to view the source lines referenced in an
165 exception traceback.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000166
Ned Deilyc859bd22012-10-20 13:23:25 -0700167Debugger
168 Run commands in the shell under the debugger.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000169
Ned Deilyc859bd22012-10-20 13:23:25 -0700170Stack viewer
171 Show the stack traceback of the last exception.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000172
Ned Deilyc859bd22012-10-20 13:23:25 -0700173Auto-open Stack Viewer
174 Open stack viewer on traceback.
Georg Brandl8ec7f652007-08-15 14:28:01 +0000175
176.. index::
177 single: stack viewer
178 single: debugger
179
180
Ned Deilyc859bd22012-10-20 13:23:25 -0700181Edit context menu
182^^^^^^^^^^^^^^^^^
183
184* Right-click in Edit window (Control-click on OS X)
185
186Set Breakpoint
187 Sets a breakpoint. Breakpoints are only enabled when the debugger is open.
188
189Clear Breakpoint
190 Clears the breakpoint on that line.
191
192.. index::
193 single: Set Breakpoint
194 single: Clear Breakpoint
195 single: breakpoints
196
197
198Shell context menu
199^^^^^^^^^^^^^^^^^^
200
201* Right-click in Python Shell window (Control-click on OS X)
202
203Go to file/line
204 Same as in Debug menu.
205
206
Georg Brandl8ec7f652007-08-15 14:28:01 +0000207Basic editing and navigation
208----------------------------
209
210* :kbd:`Backspace` deletes to the left; :kbd:`Del` deletes to the right
211
212* Arrow keys and :kbd:`Page Up`/:kbd:`Page Down` to move around
213
214* :kbd:`Home`/:kbd:`End` go to begin/end of line
215
216* :kbd:`C-Home`/:kbd:`C-End` go to begin/end of file
217
218* Some :program:`Emacs` bindings may also work, including :kbd:`C-B`,
219 :kbd:`C-P`, :kbd:`C-A`, :kbd:`C-E`, :kbd:`C-D`, :kbd:`C-L`
220
221
222Automatic indentation
223^^^^^^^^^^^^^^^^^^^^^
224
225After a block-opening statement, the next line is indented by 4 spaces (in the
226Python Shell window by one tab). After certain keywords (break, return etc.)
227the next line is dedented. In leading indentation, :kbd:`Backspace` deletes up
228to 4 spaces if they are there. :kbd:`Tab` inserts 1-4 spaces (in the Python
229Shell window one tab). See also the indent/dedent region commands in the edit
230menu.
231
232
233Python Shell window
234^^^^^^^^^^^^^^^^^^^
235
236* :kbd:`C-C` interrupts executing command
237
238* :kbd:`C-D` sends end-of-file; closes window if typed at a ``>>>`` prompt
239
240* :kbd:`Alt-p` retrieves previous command matching what you have typed
241
242* :kbd:`Alt-n` retrieves next
243
244* :kbd:`Return` while on any previous command retrieves that command
245
246* :kbd:`Alt-/` (Expand word) is also useful here
247
248.. index:: single: indentation
249
250
251Syntax colors
252-------------
253
254The coloring is applied in a background "thread," so you may occasionally see
255uncolorized text. To change the color scheme, edit the ``[Colors]`` section in
256:file:`config.txt`.
257
258Python syntax colors:
259 Keywords
260 orange
261
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000262 Strings
Georg Brandl8ec7f652007-08-15 14:28:01 +0000263 green
264
265 Comments
266 red
267
268 Definitions
269 blue
270
271Shell colors:
272 Console output
273 brown
274
275 stdout
276 blue
277
278 stderr
279 dark green
280
281 stdin
282 black
283
284
Georg Brandl09827eb2009-03-15 21:51:48 +0000285Startup
286-------
287
288Upon startup with the ``-s`` option, IDLE will execute the file referenced by
289the environment variables :envvar:`IDLESTARTUP` or :envvar:`PYTHONSTARTUP`.
290Idle first checks for ``IDLESTARTUP``; if ``IDLESTARTUP`` is present the file
291referenced is run. If ``IDLESTARTUP`` is not present, Idle checks for
292``PYTHONSTARTUP``. Files referenced by these environment variables are
293convenient places to store functions that are used frequently from the Idle
294shell, or for executing import statements to import common modules.
295
296In addition, ``Tk`` also loads a startup file if it is present. Note that the
297Tk file is loaded unconditionally. This additional file is ``.Idle.py`` and is
298looked for in the user's home directory. Statements in this file will be
299executed in the Tk namespace, so this file is not useful for importing functions
300to be used from Idle's Python shell.
301
302
Georg Brandl8ec7f652007-08-15 14:28:01 +0000303Command line usage
304^^^^^^^^^^^^^^^^^^
305
306::
307
308 idle.py [-c command] [-d] [-e] [-s] [-t title] [arg] ...
309
310 -c command run this command
311 -d enable debugger
312 -e edit mode; arguments are files to be edited
313 -s run $IDLESTARTUP or $PYTHONSTARTUP first
314 -t title set title of shell window
315
316If there are arguments:
317
Éric Araujoa8132ec2010-12-16 03:53:53 +0000318#. If ``-e`` is used, arguments are files opened for editing and
Georg Brandl8ec7f652007-08-15 14:28:01 +0000319 ``sys.argv`` reflects the arguments passed to IDLE itself.
320
Éric Araujoa8132ec2010-12-16 03:53:53 +0000321#. Otherwise, if ``-c`` is used, all arguments are placed in
Georg Brandl8ec7f652007-08-15 14:28:01 +0000322 ``sys.argv[1:...]``, with ``sys.argv[0]`` set to ``'-c'``.
323
Éric Araujoa8132ec2010-12-16 03:53:53 +0000324#. Otherwise, if neither ``-e`` nor ``-c`` is used, the first
Georg Brandl8ec7f652007-08-15 14:28:01 +0000325 argument is a script which is executed with the remaining arguments in
326 ``sys.argv[1:...]`` and ``sys.argv[0]`` set to the script name. If the script
327 name is '-', no script is executed but an interactive Python session is started;
328 the arguments are still available in ``sys.argv``.
329
330