📄 224.html
字号:
<Img bOrder="0" WidtH="500" HEIght="206" sRC="graphics/16fig01.gif" ALt="graphics/16fig01.gif">
</cenTER>
<P>IDLE provides automatic support for indentation, which is fired when you press the ENTER key after a block-opening statement. Pressing the BACKSPACE key moves you back to one level of the indentation structure. Note that this automatically happens when you insert a return, continue, break, pass, or raise statement.<a namE="idx1073749647"></A>
<A Name="idx1073749648"></a>
<a name="idx1073749649"></a>
<a name="idx1073749650"></a>
<a namE="idx1073749651"></a>
</p>
<P>
<a naMe="idx1073749652"></a>
<a nAme="idx1073749653"></a>Indentation options, including the indent level, can be fully configured, depending on your own choice. The default value of the indent level sets the tabulation to be equivalent to four spaces. An interesting feature is that it is possible to select a specific region and indent or dedent it (these options are available on the edit menu).</P>
<P>
<A Name="idx1073749654"></a>
<A NAMe="idx1073749655"></a>Tip boxes are a new sensation in this latest version of IDLE. They are displayed when you type the opening parenthesis of functions (regular or built-in) and method calls (including class constructors) from the Python Standard Library. Their contents usually show a tip that lists the expected arguments. This feature is not limited to the functions defined by the Python environment. You can also use it while coding your own functions to automatically display their list of expected arguments. In addition to the list of arguments, you can also include an additional string to your tip box by adding a <a nAME="idx1073749656"></A>
<a namE="idx1073749657"></A>
<I>documentation string</I> to your function/method definition. To close the tip window, you need to press ESC or click somewhere else in the window.</p>
<p>Another new feature introduced in this version is the <a name="idx1073749658"></a>word completion mechanism. Based on the list of the latest words introduced to the program, you can successively press ALT+/ to toggle between them in order to expand and complete the word that you have just started typing.</p>
<p>Something very interesting, but actually not new because it came from the previous version, is the <a name="idx1073749659"></a>command history mechanism. It works when you move the cursor to the end of a specific line, or block, and press ENTER. This action copies the whole line (or block) to the primary prompt. Alternatively, you can use the keys ALT+p and ALT+n to toggle between the latest commands matching what you have typed. When you find the one you want to use, press ENTER and the command is retrieved.</p>
<p>Note that you can freely edit the commands before really executing them (see <a hRef="224#5.html">Figure 16.2</A>).<a naMe="idx1073749660"></a>
<a nAme="idx1073749661"></a>
<A NAMe="idx1073749662"></a>
<a nAME="idx1073749663"></A>
<a namE="idx1073749664"></A>
</P>
<CenteR>
<H5>
<A Name="5"></a>Figure 16.2. This example demonstrates how IDLE handles indentation, the word completion mechanism, and the call tips functionality.</h5>
<img border="0" width="500" hEigHt="210" srC="graphics/16fig02.gif" alt="graphics/16fig02.gif">
</cEnteR>
<P>In case you want to <A Name="idx1073749665"></a>
<A NAMe="idx1073749666"></a>
<a nAME="idx1073749667"></A>
<a namE="idx1073749668"></A>
<A Name="idx1073749669"></a>change the current font used on windows, you just need to open the <tt class="monofont">EditorWindow.py</tt> file and define a new tuple value for the <tt class="monofont">font</Tt> entry in the <tT claSs="monofont">text</tt> dictionary, such as</p>
<Pre>
text['font'] = ("times", 12)
</pRE>
<H4>
Keyboard Commands</H4>
<p>Moving around in the IDLE buffer is fairly easy. For basic editing and navigation controls, you can use the following key bindings:</p>
<ul>
<LI>
<P>Backspace deletes to the left of the cursor.</P>
</li>
<li>
<P>DEL deletes to the right of the cursor.</P>
</LI>
<li>
<p>Arrow keys and Page Up/Down are used to move around the buffer.</p>
</LI>
<LI>
<p>Home goes to the beginning of the line.</p>
</li>
<li>
<p>End goes to the end of the line.</p>
</li>
<li>
<p>CTRL+Home goes to the beginning of the file.</p>
</li>
<li>
<p>CTRL+End goes to the end of the file.</p>
</Li>
</uL>
<p>IDLE offers you the chance to modify some of the keyboard binding settings. Check out the <tt Class="monofont">Bindings.py</Tt> file for details.<a nAME="idx1073749670"></A>
<a namE="idx1073749671"></A>
<A Name="idx1073749672"></a>
<A NAMe="idx1073749673"></a>
</p>
<h4>
File Menu</H4>
<P>IDLE's File Editor allows you to create new scripts or browse and edit existing Python source files. The File Editor might also be brought up from the Path Browser or when you are using the Debugger. In all cases, a new File Editor window will be opened with the name of the file and the path to it as its title (or called Untitled if it is a new unsaved file).<A Name="idx1073749674"></a>
<a name="idx1073749675"></a>
<a name="idx1073749676"></a>
<a namE="idx1073749677"></a>
</p>
<Div cLass="note"><p ClasS="notetitle"><B>Tip</B></P><p>
<p>A nice feature is almost hidden in the shell environment. If you click on the dotted line at the top of a menu, a new window is created containing the menu itself.</p>
</p></DIV>
<Br>
<br>
<p>The following <A NAMe="idx1073749678"></a>
<a nAME="idx1073749679"></A>
<a name="idx1073749680"></a>options are menu items located in the File menu:</p>
<blockquote>
<p>
<p>
<a NamE="idx1073749681"></a>New window桟reates and opens a new editing window for when you want to create a new Python source file.</p>
</p>
<P>
<p>
<a naMe="idx1073749682"></a>Open...桹pens a dialog box that allows you to locate and open any Python source file on your local system.</p>
</P>
<P>
<P>
<A name="idx1073749683"></A>Open module...桝sks you to enter the name of a module, and then it searches through all the directories listed in the <TT Class="monofont">sys.path.</TT> The module is opened after it has been found.</P>
</P>
<p>
<p>
<a nAME="idx1073749684"></A>Class browser桹pens a small utility that shows the classes and methods stored in the current open file.</p>
</p>
<p>
<p>
<a name="idx1073749685"></a>Path browser桿ses the <tt class="monofont">sys.path</tt> variable as a startup helper for letting you browse directories, modules, classes, and methods.</p>
</P>
<p>
<p>
<A namE="idx1073749686"></a>Save桽aves the current window. If the title of the window is delimited by <tt cLass="monofont">*</TT> literals, it indicates that the window has changed since the last time you saved it.</P>
</P>
<p>
<p>
<a nAME="idx1073749687"></A>Save As...桽aves the current window using the given filename.</p>
</p>
<p>
<p>
<A NAMe="idx1073749688"></a>Save Copy As...桽aves the current window using the given filename. The difference when comparing this to the previous option, is that this one doesn't rename the current window as the name of the new file.</p>
</p>
<P>
<P>
<A Name="idx1073749689"></a>Close桟loses the current window.</p>
</p>
<p>
<p>
<a name="idx1073749690"></a>Exit桿sed to leave IDLE. It closes all windows and quits.<a name="idx1073749691"></a>
<A naMe="idx1073749692"></a>
<a Name="idx1073749693"></a>
</P>
</p>
</blOCKQuote>
<P>The following table lists some <A NAme="idx1073749694"></a>
<a NAME="idx1073749695"></a>Emacs and Windows bindings for the previous set of Menu Options.<a naME="idx1073749696"></A>
<A name="idx1073749697"></a>
<a name="idx1073749698"></a>
</p>
<p><table boRdeR="1" celLspacIng="0" cELLPaddiNG="1" WIdth="100%">
<cAPTIon><h5>Table
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -