“Python/docs/3.9/library/idle”的版本间差异

来自菜鸟教程
Python/docs/3.9/library/idle
跳转至:导航、​搜索
(autoload)
 
(Page commit)
 
第1行: 第1行:
 +
{{DISPLAYTITLE:空闲 — Python 文档}}
 
<div id="idle" class="section">
 
<div id="idle" class="section">
  
 
<span id="id1"></span>
 
<span id="id1"></span>
= IDLE =
+
= 空闲 =
  
'''Source code:''' [https://github.com/python/cpython/tree/3.9/Lib/idlelib/ Lib/idlelib/]
+
'''源代码:''' [[#id2|<span id="id3" class="problematic">:source:`库/空闲库/`</span>]]
  
IDLE is Python's Integrated Development and Learning Environment.
 
  
IDLE has the following features:
+
-----
  
* coded in 100% pure Python, using the [[../tkinter#module-tkinter|<code>tkinter</code>]] GUI toolkit
+
IDLE 是 Python 的集成开发和学习环境。
* cross-platform: works mostly the same on Windows, Unix, and macOS
+
 
* Python shell window (interactive interpreter) with colorizing of code input, output, and error messages
+
IDLE具有以下特点:
* multi-window text editor with multiple undo, Python colorizing, smart indent, call tips, auto completion, and other features
+
 
* search within any window, replace within editor windows, and search through multiple files (grep)
+
* 100% Python 编码,使用 [[../tkinter#module-tkinter|tkinter]] GUI 工具包
* debugger with persistent breakpoints, stepping, and viewing of global and local namespaces
+
* 跨平台:在 Windows、Unix 和 macOS 上的工作方式大致相同
* configuration, browsers, and other dialogs
+
* 带有代码输入、输出和错误消息着色的 Python shell 窗口(交互式解释器)
 +
* 具有多个撤销、Python 着色、智能缩进、调用提示、自动完成和其他功能的多窗口文本编辑器
 +
* 在任何窗口中搜索,在编辑器窗口中替换,并搜索多个文件 (grep)
 +
* 具有持久断点、步进和查看全局和本地命名空间的调试器
 +
* 配置、浏览器和其他对话框
  
 
<div id="menus" class="section">
 
<div id="menus" class="section">
  
== Menus ==
+
== 菜单 ==
  
IDLE has two main window types, the Shell window and the Editor window. It is
+
IDLE 有两种主要的窗口类型,Shell 窗口和 Editor 窗口。 可以同时拥有多个编辑器窗口。 在 Windows Linux 上,每个都有自己的顶部菜单。 下面记录的每个菜单都指示了它与哪种窗口类型相关联。
possible to have multiple editor windows simultaneously. On Windows and
 
Linux, each has its own top menu. Each menu documented below indicates
 
which window type it is associated with.
 
  
Output windows, such as used for Edit =&gt; Find in Files, are a subtype of editor
+
输出窗口,例如用于编辑 =&gt; 在文件中查找,是编辑器窗口的子类型。 它们目前具有相同的顶部菜单,但具有不同的默认标题和上下文菜单。
window. They currently have the same top menu but a different
 
default title and context menu.
 
  
On macOS, there is one application menu. It dynamically changes according
+
macOS 上,有一个应用程序菜单。 它根据当前选择的窗口动态变化。 它有一个空闲菜单,下面描述的一些条目被移动以符合 Apple 指南。
to the window currently selected. It has an IDLE menu, and some entries
 
described below are moved around to conform to Apple guidelines.
 
  
 
<div id="file-menu-shell-and-editor" class="section">
 
<div id="file-menu-shell-and-editor" class="section">
  
=== File menu (Shell and Editor) ===
+
=== 文件菜单(Shell 和编辑器) ===
  
; New File
+
; 新文件
: Create a new file editing window.
+
: 创建一个新的文件编辑窗口。
; Open...
+
; 打开…
: Open an existing file with an Open dialog.
+
: 使用“打开”对话框打开现有文件。
; Recent Files
+
; 最近的文件
: Open a list of recent files. Click one to open it.
+
: 打开最近文件列表。 单击一个打开它。
; Open Module...
+
; 打开模块…
: Open an existing module (searches sys.path).
+
: 打开现有模块(搜索 sys.path)。
  
; Class Browser
+
; 类浏览器
: Show functions, classes, and methods in the current Editor file in a tree structure. In the shell, open a module first.
+
: 以树结构显示当前编辑器文件中的函数、类和方法。 在 shell 中,首先打开一个模块。
; Path Browser
+
; 路径浏览器
: Show sys.path directories, modules, functions, classes and methods in a tree structure.
+
: 以树状结构显示 sys.path 目录、模块、函数、类和方法。
; Save
+
; 节省
: Save the current window to the associated file, if there is one. Windows that have been changed since being opened or last saved have a * before and after the window title. If there is no associated file, do Save As instead.
+
: 将当前窗口保存到关联文件(如果有)。 自打开或上次保存以来已更改的窗口在窗口标题前后都有一个 *。 如果没有关联文件,请改为另存为。
; Save As...
+
; 另存为…
: Save the current window with a Save As dialog. The file saved becomes the new associated file for the window.
+
: 使用另存为对话框保存当前窗口。 保存的文件成为窗口的新关联文件。
; Save Copy As...
+
; 将副本另存为…
: Save the current window to different file without changing the associated file.
+
: 将当前窗口保存到不同的文件而不更改关联的文件。
; Print Window
+
; 打印窗口
: Print the current window to the default printer.
+
: 将当前窗口打印到默认打印机。
; Close
+
;
: Close the current window (ask to save if unsaved).
+
: 关闭当前窗口(如果未保存则要求保存)。
; Exit
+
; 出口
: Close all windows and quit IDLE (ask to save unsaved windows).
+
: 关闭所有窗口并退出 IDLE(要求保存未保存的窗口)。
  
  
第69行: 第66行:
 
<div id="edit-menu-shell-and-editor" class="section">
 
<div id="edit-menu-shell-and-editor" class="section">
  
=== Edit menu (Shell and Editor) ===
+
=== 编辑菜单(Shell 和编辑器) ===
  
; Undo
+
; 撤消
: Undo the last change to the current window. A maximum of 1000 changes may be undone.
+
: 撤消对当前窗口的最后更改。 最多可以撤消 1000 次更改。
; Redo
+
; 重做
: Redo the last undone change to the current window.
+
: 将上次撤消的更改重做当前窗口。
; Cut
+
;
: Copy selection into the system-wide clipboard; then delete the selection.
+
: 将选择复制到系统范围的剪贴板中; 然后删除选择。
; Copy
+
; 复制
: Copy selection into the system-wide clipboard.
+
: 将选择复制到系统范围的剪贴板中。
; Paste
+
; 粘贴
: Insert contents of the system-wide clipboard into the current window.
+
: 将系统范围剪贴板的内容插入当前窗口。
  
The clipboard functions are also available in context menus.
+
剪贴板功能也可在上下文菜单中使用。
  
; Select All
+
; 全选
: Select the entire contents of the current window.
+
: 选择当前窗口的全部内容。
; Find...
+
; 找…
: Open a search dialog with many options
+
: 打开带有许多选项的搜索对话框
; Find Again
+
; 再次查找
: Repeat the last search, if there is one.
+
: 重复上一次搜索,如果有的话。
; Find Selection
+
; 查找选择
: Search for the currently selected string, if there is one.
+
: 搜索当前选定的字符串(如果有)。
; Find in Files...
+
; 在文件中查找…
: Open a file search dialog. Put results in a new output window.
+
: 打开文件搜索对话框。 将结果放在新的输出窗口中。
; Replace...
+
; 代替…
: Open a search-and-replace dialog.
+
: 打开搜索和替换对话框。
; Go to Line
+
; 去线
: Move the cursor to the beginning of the line requested and make that line visible. A request past the end of the file goes to the end. Clear any selection and update the line and column status.
+
: 将光标移动到所请求行的开头并使该行可见。 超过文件末尾的请求将结束。 清除任何选择并更新行和列状态。
; Show Completions
+
; 显示完成
: Open a scrollable list allowing selection of existing names. See [[#completions|<span class="std std-ref">Completions</span>]] in the Editing and navigation section below.
+
: 打开一个可滚动列表,允许选择现有名称。 请参阅下面编辑和导航部分中的 [[#completions|完成]]
; Expand Word
+
; 展开字
: Expand a prefix you have typed to match a full word in the same window; repeat to get a different expansion.
+
: 展开您输入的前缀以匹配同一窗口中的完整单词; 重复以获得不同的扩展。
; Show call tip
+
; 显示通话提示
: After an unclosed parenthesis for a function, open a small window with function parameter hints. See [[#calltips|<span class="std std-ref">Calltips</span>]] in the Editing and navigation section below.
+
: 在函数的未闭括号之后,打开一个带有函数参数提示的小窗口。 请参阅下面编辑和导航部分中的 [[#calltips|调用提示]]
; Show surrounding parens
+
; 显示周围的括号
: Highlight the surrounding parenthesis.
+
: 突出显示周围的括号。
  
  
第112行: 第109行:
  
 
<span id="format-menu"></span>
 
<span id="format-menu"></span>
=== Format menu (Editor window only) ===
+
=== 格式菜单(仅限编辑器窗口) ===
  
; Indent Region
+
; 缩进区域
: Shift selected lines right by the indent width (default 4 spaces).
+
: 将所选行向右移动缩进宽度(默认为 4 个空格)。
; Dedent Region
+
; 凹陷区域
: Shift selected lines left by the indent width (default 4 spaces).
+
: 将选定的行向左移动缩进宽度(默认为 4 个空格)。
; Comment Out Region
+
; 注释掉区域
: Insert ## in front of selected lines.
+
: 在所选行前插入##
; Uncomment Region
+
; 取消注释区域
: Remove leading # or ## from selected lines.
+
: 从选定的行中删除前导 # ##
; Tabify Region
+
; Tabify 区域
: Turn ''leading'' stretches of spaces into tabs. (Note: We recommend using 4 space blocks to indent Python code.)
+
: ''前导'' 段空格转换为制表符。 (注意:我们建议使用 4 个空格块来缩进 Python 代码。)
; Untabify Region
+
; 取消标签区域
: Turn ''all'' tabs into the correct number of spaces.
+
: ''全部'' 制表符转换为正确数量的空格。
; Toggle Tabs
+
; 切换标签
: Open a dialog to switch between indenting with spaces and tabs.
+
: 打开一个对话框以在使用空格和制表符缩进之间切换。
; New Indent Width
+
; 新缩进宽度
: Open a dialog to change indent width. The accepted default by the Python community is 4 spaces.
+
: 打开一个对话框以更改缩进宽度。 Python 社区接受的默认值是 4 个空格。
; Format Paragraph
+
; 格式段落
: Reformat the current blank-line-delimited paragraph in comment block or multiline string or selected line in a string. All lines in the paragraph will be formatted to less than N columns, where N defaults to 72.
+
: 在注释块或多行字符串或字符串中的选定行中重新格式化当前以空行分隔的段落。 段落中的所有行都将被格式化为少于 N 列,其中 N 默认为 72。
; Strip trailing whitespace
+
; 去除尾随空格
: Remove trailing space and other whitespace characters after the last non-whitespace character of a line by applying str.rstrip to each line, including lines within multiline strings. Except for Shell windows, remove extra newlines at the end of the file.
+
: 通过将 str.rstrip 应用于每行(包括多行字符串中的行),删除行的最后一个非空白字符之后的尾随空格和其他空白字符。 除了 Shell 窗口,删除文件末尾的额外换行符。
  
  
第140行: 第137行:
  
 
<span id="index-2"></span>
 
<span id="index-2"></span>
=== Run menu (Editor window only) ===
+
=== 运行菜单(仅限编辑器窗口) ===
  
; Run Module
+
; 运行模块
: Do [[#check-module|<span class="std std-ref">Check Module</span>]]. If no error, restart the shell to clean the environment, then execute the module. Output is displayed in the Shell window. Note that output requires use of <code>print</code> or <code>write</code>. When execution is complete, the Shell retains focus and displays a prompt. At this point, one may interactively explore the result of execution. This is similar to executing a file with <code>python -i file</code> at a command line.
+
: [[#check-module|检查模块]]。 如果没有报错,重启shell清理环境,然后执行模块。 输出显示在 Shell 窗口中。 请注意,输出需要使用 <code>print</code> <code>write</code>。 执行完成后,Shell 保持焦点并显示提示。 在这一点上,可以交互式地探索执行的结果。 这类似于在命令行中使用 <code>python -i file</code> 执行文件。
  
; Run... Customized
+
; 运行... 定制
: Same as [[#run-module|<span class="std std-ref">Run Module</span>]], but run the module with customized settings. ''Command Line Arguments'' extend [[../sys#sys|<code>sys.argv</code>]] as if passed on a command line. The module can be run in the Shell without restarting.
+
: [[#run-module|Run Module]] 相同,但使用自定义设置运行模块。 ''命令行参数'' 扩展 [[../sys#sys|sys.argv]] 就像在命令行上传递一样。 该模块无需重启即可在 Shell 中运行。
  
; Check Module
+
; 检查模块
: Check the syntax of the module currently open in the Editor window. If the module has not been saved IDLE will either prompt the user to save or autosave, as selected in the General tab of the Idle Settings dialog. If there is a syntax error, the approximate location is indicated in the Editor window.
+
: 检查当前在编辑器窗口中打开的模块的语法。 如果模块尚未保存,IDLE 将提示用户保存或自动保存,如在空闲设置对话框的常规选项卡中选择的那样。 如果存在语法错误,则在“编辑器”窗口中会指示大致位置。
  
; Python Shell
+
; 蟒蛇壳
: Open or wake up the Python Shell window.
+
: 打开或唤醒 Python Shell 窗口。
  
  
第158行: 第155行:
 
<div id="shell-menu-shell-window-only" class="section">
 
<div id="shell-menu-shell-window-only" class="section">
  
=== Shell menu (Shell window only) ===
+
=== Shell 菜单(仅限 Shell 窗口) ===
  
; View Last Restart
+
; 查看上次重启
: Scroll the shell window to the last Shell restart.
+
: shell 窗口滚动到最后一次 shell 重新启动。
; Restart Shell
+
; 重启外壳
: Restart the shell to clean the environment.
+
: 重新启动 shell 以清理环境并重置显示和异常处理。
; Previous History
+
; 过往历史
: Cycle through earlier commands in history which match the current entry.
+
: 循环浏览历史记录中与当前条目匹配的较早命令。
; Next History
+
; 下一个历史
: Cycle through later commands in history which match the current entry.
+
: 循环浏览历史记录中与当前条目匹配的后续命令。
; Interrupt Execution
+
; 中断执行
: Stop a running program.
+
: 停止正在运行的程序。
  
  
第175行: 第172行:
 
<div id="debug-menu-shell-window-only" class="section">
 
<div id="debug-menu-shell-window-only" class="section">
  
=== Debug menu (Shell window only) ===
+
=== 调试菜单(仅限 Shell 窗口) ===
  
; Go to File/Line
+
; 转到文件/
: Look on the current line. with the cursor, and the line above for a filename and line number. If found, open the file if not already open, and show the line. Use this to view source lines referenced in an exception traceback and lines found by Find in Files. Also available in the context menu of the Shell window and Output windows.
+
: 查看当前行。 用光标和上面的行作为文件名和行号。 如果找到,则打开文件(如果尚未打开)并显示该行。 使用它来查看异常回溯中引用的源代码行和在文件中查找找到的行。 也可在 Shell 窗口和输出窗口的上下文菜单中使用。
  
; Debugger (toggle)
+
; 调试器(切换)
: When activated, code entered in the Shell or run from an Editor will run under the debugger. In the Editor, breakpoints can be set with the context menu. This feature is still incomplete and somewhat experimental.
+
: 激活后,在 Shell 中输入或从编辑器运行的代码将在调试器下运行。 在编辑器中,可以使用上下文菜单设置断点。 此功能仍然不完整,并且有些实验性。
; Stack Viewer
+
; 堆栈查看器
: Show the stack traceback of the last exception in a tree widget, with access to locals and globals.
+
: 在树小部件中显示最后一个异常的堆栈回溯,可以访问局部变量和全局变量。
; Auto-open Stack Viewer
+
; 自动打开堆栈查看器
: Toggle automatically opening the stack viewer on an unhandled exception.
+
: 在未处理的异常上切换自动打开堆栈查看器。
  
  
第191行: 第188行:
 
<div id="options-menu-shell-and-editor" class="section">
 
<div id="options-menu-shell-and-editor" class="section">
  
=== Options menu (Shell and Editor) ===
+
=== 选项菜单(Shell 和编辑器) ===
  
; Configure IDLE
+
; 配置空闲
: Open a configuration dialog and change preferences for the following: fonts, indentation, keybindings, text color themes, startup windows and size, additional help sources, and extensions. On macOS, open the configuration dialog by selecting Preferences in the application menu. For more details, see [[#preferences|<span class="std std-ref">Setting preferences</span>]] under Help and preferences.
+
: 打开配置对话框并更改以下项的首选项:字体、缩进、键绑定、文本颜色主题、启动窗口和大小、其他帮助源和扩展。 在 macOS 上,通过在应用程序菜单中选择首选项来打开配置对话框。 有关更多详细信息,请参阅帮助和首选项下的 [[#preferences|设置首选项]]
  
Most configuration options apply to all windows or all future windows.
+
大多数配置选项适用于所有窗口或所有未来的窗口。 以下选项仅适用于活动窗口。
The option items below only apply to the active window.
 
  
; Show/Hide Code Context (Editor Window only)
+
; 显示/隐藏代码上下文(仅限编辑器窗口)
: Open a pane at the top of the edit window which shows the block context of the code which has scrolled above the top of the window. See [[#code-context|<span class="std std-ref">Code Context</span>]] in the Editing and Navigation section below.
+
: 在编辑窗口顶部打开一个窗格,其中显示滚动到窗口顶部上方的代码的块上下文。 请参阅下面编辑和导航部分中的 [[#code-context|代码上下文]]
; Show/Hide Line Numbers (Editor Window only)
+
; 显示/隐藏行号(仅限编辑器窗口)
: Open a column to the left of the edit window which shows the number of each line of text. The default is off, which may be changed in the preferences (see [[#preferences|<span class="std std-ref">Setting preferences</span>]]).
+
: 在编辑窗口左侧打开一列,显示每行文本的编号。 默认为关闭,可在首选项中更改(请参阅 [[#preferences|设置首选项]] )。
; Zoom/Restore Height
+
; 缩放/恢复高度
: Toggles the window between normal size and maximum height. The initial size defaults to 40 lines by 80 chars unless changed on the General tab of the Configure IDLE dialog. The maximum height for a screen is determined by momentarily maximizing a window the first time one is zoomed on the screen. Changing screen settings may invalidate the saved height. This toggle has no effect when a window is maximized.
+
: 在正常大小和最大高度之间切换窗口。 初始大小默认为 40 行 x 80 个字符,除非在 Configure IDLE 对话框的 General 选项卡上进行更改。 屏幕的最大高度是通过在第一次放大屏幕时暂时最大化窗口来确定的。 更改屏幕设置可能会使保存的高度无效。 当窗口最大化时,此切换不起作用。
  
  
第210行: 第206行:
 
<div id="window-menu-shell-and-editor" class="section">
 
<div id="window-menu-shell-and-editor" class="section">
  
=== Window menu (Shell and Editor) ===
+
=== 窗口菜单(Shell 和编辑器) ===
  
Lists the names of all open windows; select one to bring it to the foreground
+
列出所有打开的窗口的名称; 选择一个将其置于前台(如有必要,将其取消图标化)。
(deiconifying it if necessary).
 
  
  
第219行: 第214行:
 
<div id="help-menu-shell-and-editor" class="section">
 
<div id="help-menu-shell-and-editor" class="section">
  
=== Help menu (Shell and Editor) ===
+
=== 帮助菜单(Shell 和编辑器) ===
  
; About IDLE
+
; 关于空闲
: Display version, copyright, license, credits, and more.
+
: 显示版本、版权、许可、信用等。
; IDLE Help
+
; 空闲帮助
: Display this IDLE document, detailing the menu options, basic editing and navigation, and other tips.
+
: 显示此 IDLE 文档,详细说明菜单选项、基本编辑和导航以及其他提示。
; Python Docs
+
; Python 文档
: Access local Python documentation, if installed, or start a web browser and open docs.python.org showing the latest Python documentation.
+
: 访问本地 Python 文档(如果已安装),或启动 Web 浏览器并打开显示最新 Python 文档的 docs.python.org。
; Turtle Demo
+
; 海龟演示
: Run the turtledemo module with example Python code and turtle drawings.
+
: 运行带有示例 Python 代码和海龟绘图的turtledemo 模块。
  
Additional help sources may be added here with the Configure IDLE dialog under
+
可以使用“常规”选项卡下的“配置空闲”对话框在此处添加其他帮助源。 有关帮助菜单选项的更多信息,请参阅下面的 [[#help-sources|帮助源]] 小节。
the General tab. See the [[#help-sources|<span class="std std-ref">Help sources</span>]] subsection below
 
for more on Help menu choices.
 
  
  
第239行: 第232行:
  
 
<span id="index-4"></span>
 
<span id="index-4"></span>
=== Context Menus ===
+
=== 上下文菜单 ===
  
Open a context menu by right-clicking in a window (Control-click on macOS).
+
通过右键单击窗口(在 macOS 上按住 Control 单击)打开上下文菜单。 上下文菜单也具有编辑菜单上的标准剪贴板功能。
Context menus have the standard clipboard functions also on the Edit menu.
 
  
; Cut
+
;
: Copy selection into the system-wide clipboard; then delete the selection.
+
: 将选择复制到系统范围的剪贴板中; 然后删除选择。
; Copy
+
; 复制
: Copy selection into the system-wide clipboard.
+
: 将选择复制到系统范围的剪贴板中。
; Paste
+
; 粘贴
: Insert contents of the system-wide clipboard into the current window.
+
: 将系统范围剪贴板的内容插入当前窗口。
  
Editor windows also have breakpoint functions. Lines with a breakpoint set are
+
编辑器窗口也有断点功能。 设置断点的行被特别标记。 断点仅在调试器下运行时有效。 文件的断点保存在用户的 <code>.idlerc</code> 目录中。
specially marked. Breakpoints only have an effect when running under the
 
debugger. Breakpoints for a file are saved in the user's <code>.idlerc</code>
 
directory.
 
  
; Set Breakpoint
+
; 设置断点
: Set a breakpoint on the current line.
+
: 在当前行上设置断点。
; Clear Breakpoint
+
; 清除断点
: Clear the breakpoint on that line.
+
: 清除该行上的断点。
  
Shell and Output windows also have the following.
+
Shell Output 窗口也有以下内容。
  
; Go to file/line
+
; 转到文件/
: Same as in Debug menu.
+
: 与调试菜单中的相同。
  
The Shell window also has an output squeezing facility explained in the ''Python
+
Shell 窗口还有一个输出压缩工具,在下面的 ''Python Shell 窗口'' 小节中进行了解释。
Shell window'' subsection below.
 
  
; Squeeze
+
;
: If the cursor is over an output line, squeeze all the output between the code above and the prompt below down to a 'Squeezed text' label.
+
: 如果光标位于输出行上,将上面代码和下面提示之间的所有输出压缩到“压缩文本”标签。
  
  
第278行: 第266行:
 
<div id="editing-and-navigation" class="section">
 
<div id="editing-and-navigation" class="section">
  
<span id="id2"></span>
+
<span id="id4"></span>
== Editing and navigation ==
+
== 编辑和导航 ==
  
 
<div id="editor-windows" class="section">
 
<div id="editor-windows" class="section">
  
=== Editor windows ===
+
=== 编辑器窗口 ===
  
IDLE may open editor windows when it starts, depending on settings
+
IDLE 可能会在启动时打开编辑器窗口,具体取决于设置和您启动 IDLE 的方式。 此后,使用文件菜单。 给定文件只能有一个打开的编辑器窗口。
and how you start IDLE. Thereafter, use the File menu. There can be only
 
one open editor window for a given file.
 
  
The title bar contains the name of the file, the full path, and the version
+
标题栏包含文件名、完整路径以及运行窗口的 Python IDLE 版本。 状态栏包含行号 ('Ln') 和列号 ('Col')。 行号从 1 开始; 列号为 0。
of Python and IDLE running the window. The status bar contains the line
 
number ('Ln') and column number ('Col'). Line numbers start with 1;
 
column numbers with 0.
 
  
IDLE assumes that files with a known .py* extension contain Python code
+
IDLE 假定具有已知 .py* 扩展名的文件包含 Python 代码,而其他文件不包含。 使用运行菜单运行 Python 代码。
and that other files do not. Run Python code with the Run menu.
 
  
  
第301行: 第283行:
 
<div id="key-bindings" class="section">
 
<div id="key-bindings" class="section">
  
=== Key bindings ===
+
=== 键绑定 ===
  
In this section, 'C' refers to the <span class="kbd kbd docutils literal notranslate">Control</span> key on Windows and Unix and
+
在本节中,“C”指的是 Windows 和 Unix 上的 <span class="kbd kbd docutils literal notranslate">Control</span> 键以及 macOS 上的 <span class="kbd kbd docutils literal notranslate">Command</span> 键。
the <span class="kbd kbd docutils literal notranslate">Command</span> key on macOS.
 
  
 
<ul>
 
<ul>
<li><p><span class="kbd kbd docutils literal notranslate">Backspace</span> deletes to the left; <span class="kbd kbd docutils literal notranslate">Del</span> deletes to the right</p></li>
+
<li><p><span class="kbd kbd docutils literal notranslate">Backspace</span> 向左删除; <span class="kbd kbd docutils literal notranslate">Del</span> 向右删除</p></li>
<li><p><span class="kbd kbd docutils literal notranslate"><span class="kbd kbd docutils literal notranslate">C</span>-<span class="kbd kbd docutils literal notranslate">Backspace</span></span> delete word left; <span class="kbd kbd docutils literal notranslate"><span class="kbd kbd docutils literal notranslate">C</span>-<span class="kbd kbd docutils literal notranslate">Del</span></span> delete word to the right</p></li>
+
<li><p><span class="kbd kbd compound docutils literal notranslate">C-Backspace</span> 删除左字; <span class="kbd kbd compound docutils literal notranslate">C-Del</span>删除右边的字</p></li>
<li><p>Arrow keys and <span class="kbd kbd docutils literal notranslate"><span class="kbd kbd docutils literal notranslate">Page</span> <span class="kbd kbd docutils literal notranslate">Up</span></span>/<span class="kbd kbd docutils literal notranslate"><span class="kbd kbd docutils literal notranslate">Page</span> <span class="kbd kbd docutils literal notranslate">Down</span></span> to move around</p></li>
+
<li><p>方向键和 <span class="kbd kbd docutils literal notranslate">Page Up</span>/<span class="kbd kbd compound docutils literal notranslate">Page Down</span> 左右移动</p></li>
<li><p><span class="kbd kbd docutils literal notranslate"><span class="kbd kbd docutils literal notranslate">C</span>-<span class="kbd kbd docutils literal notranslate">LeftArrow</span></span> and <span class="kbd kbd docutils literal notranslate"><span class="kbd kbd docutils literal notranslate">C</span>-<span class="kbd kbd docutils literal notranslate">RightArrow</span></span> moves by words</p></li>
+
<li><p><span class="kbd kbd compound docutils literal notranslate">C-LeftArrow</span> <span class="kbd kbd compound docutils literal notranslate">C-RightArrow</span> 按单词移动</p></li>
<li><p><span class="kbd kbd docutils literal notranslate">Home</span>/<span class="kbd kbd docutils literal notranslate">End</span> go to begin/end of line</p></li>
+
<li><p><span class="kbd kbd docutils literal notranslate">Home</span>/<span class="kbd kbd docutils literal notranslate">End</span>转到行首/行尾</p></li>
<li><p><span class="kbd kbd docutils literal notranslate"><span class="kbd kbd docutils literal notranslate">C</span>-<span class="kbd kbd docutils literal notranslate">Home</span></span>/<span class="kbd kbd docutils literal notranslate"><span class="kbd kbd docutils literal notranslate">C</span>-<span class="kbd kbd docutils literal notranslate">End</span></span> go to begin/end of file</p></li>
+
<li><p><span class="kbd kbd compound docutils literal notranslate">C-Home</span>/<span class="kbd kbd compound docutils literal notranslate">C-End</span> 转到文件的开头/结尾</p></li>
<li><p>Some useful Emacs bindings are inherited from Tcl/Tk:</p>
+
<li><p>一些有用的 Emacs 绑定是从 Tcl/Tk 继承的:</p>
 
<blockquote><div>
 
<blockquote><div>
  
 
<ul>
 
<ul>
<li><p><span class="kbd kbd docutils literal notranslate"><span class="kbd kbd docutils literal notranslate">C</span>-<span class="kbd kbd docutils literal notranslate">a</span></span> beginning of line</p></li>
+
<li><p><span class="kbd kbd compound docutils literal notranslate">Ca</span> 行首</p></li>
<li><p><span class="kbd kbd docutils literal notranslate"><span class="kbd kbd docutils literal notranslate">C</span>-<span class="kbd kbd docutils literal notranslate">e</span></span> end of line</p></li>
+
<li><p><span class="kbd kbd compound docutils literal notranslate">Ce</span> 行尾</p></li>
<li><p><span class="kbd kbd docutils literal notranslate"><span class="kbd kbd docutils literal notranslate">C</span>-<span class="kbd kbd docutils literal notranslate">k</span></span> kill line (but doesn't put it in clipboard)</p></li>
+
<li><p><span class="kbd kbd compound docutils literal notranslate">Ck</span> 终止线(但不将其放入剪贴板)</p></li>
<li><p><span class="kbd kbd docutils literal notranslate"><span class="kbd kbd docutils literal notranslate">C</span>-<span class="kbd kbd docutils literal notranslate">l</span></span> center window around the insertion point</p></li>
+
<li><p><span class="kbd kbd compound docutils literal notranslate">Cl</span> 插入点周围的中心窗口</p></li>
<li><p><span class="kbd kbd docutils literal notranslate"><span class="kbd kbd docutils literal notranslate">C</span>-<span class="kbd kbd docutils literal notranslate">b</span></span> go backward one character without deleting (usually you can
+
<li><p><span class="kbd kbd compound docutils literal notranslate">Cb</span> 后退一个字符而不删除(通常您也可以使用光标键进行此操作)</p></li>
also use the cursor key for this)</p></li>
+
<li><p><span class="kbd kbd compound docutils literal notranslate">Cf</span> 向前移动一个字符而不删除(通常您也可以使用光标键进行此操作)</p></li>
<li><p><span class="kbd kbd docutils literal notranslate"><span class="kbd kbd docutils literal notranslate">C</span>-<span class="kbd kbd docutils literal notranslate">f</span></span> go forward one character without deleting (usually you can
+
<li><p><span class="kbd kbd compound docutils literal notranslate">Cp</span> 上一行(通常也可以使用光标键)</p></li>
also use the cursor key for this)</p></li>
+
<li><p><span class="kbd kbd compound docutils literal notranslate">Cd</span> 删除下一个字符</p></li></ul>
<li><p><span class="kbd kbd docutils literal notranslate"><span class="kbd kbd docutils literal notranslate">C</span>-<span class="kbd kbd docutils literal notranslate">p</span></span> go up one line (usually you can also use the cursor key for
 
this)</p></li>
 
<li><p><span class="kbd kbd docutils literal notranslate"><span class="kbd kbd docutils literal notranslate">C</span>-<span class="kbd kbd docutils literal notranslate">d</span></span> delete next character</p></li></ul>
 
  
  
 
</div></blockquote></li></ul>
 
</div></blockquote></li></ul>
  
Standard keybindings (like <span class="kbd kbd docutils literal notranslate"><span class="kbd kbd docutils literal notranslate">C</span>-<span class="kbd kbd docutils literal notranslate">c</span></span> to copy and <span class="kbd kbd docutils literal notranslate"><span class="kbd kbd docutils literal notranslate">C</span>-<span class="kbd kbd docutils literal notranslate">v</span></span> to paste)
+
标准键绑定(如 <span class="kbd kbd compound docutils literal notranslate">Cc</span> 复制和 <span class="kbd kbd compound docutils literal notranslate">Cv</span> 粘贴)可能有效。 在“配置空闲”对话框中选择键绑定。
may work. Keybindings are selected in the Configure IDLE dialog.
 
  
  
第339行: 第316行:
 
<div id="automatic-indentation" class="section">
 
<div id="automatic-indentation" class="section">
  
=== Automatic indentation ===
+
=== 自动缩进 ===
  
After a block-opening statement, the next line is indented by 4 spaces (in the
+
在块开始语句之后,下一行缩进 4 个空格(在 Python Shell 窗口中缩进一个选项卡)。 在某些关键字(break、return 等)之后,下一行被缩进。 在前导缩进中,<span class="kbd kbd docutils literal notranslate">Backspace</span> 最多删除 4 个空格(如果存在)。 <span class="kbd kbd docutils literal notranslate">Tab</span> 插入空格(在 Python Shell 窗口中的一个选项卡),数量取决于缩进宽度。 目前,由于 Tcl/Tk 的限制,制表符被限制为四个空格。
Python Shell window by one tab). After certain keywords (break, return etc.)
 
the next line is dedented. In leading indentation, <span class="kbd kbd docutils literal notranslate">Backspace</span> deletes up
 
to 4 spaces if they are there. <span class="kbd kbd docutils literal notranslate">Tab</span> inserts spaces (in the Python
 
Shell window one tab), number depends on Indent width. Currently, tabs
 
are restricted to four spaces due to Tcl/Tk limitations.
 
  
See also the indent/dedent region commands on the
+
另请参阅 [[#format-menu|格式菜单]] 上的缩进/缩进区域命令。
[[#format-menu|<span class="std std-ref">Format menu</span>]].
 
  
  
第355行: 第326行:
 
<div id="completions" class="section">
 
<div id="completions" class="section">
  
<span id="id3"></span>
+
<span id="id5"></span>
=== Completions ===
+
=== 完成 ===
  
Completions are supplied, when requested and available, for module
+
在请求和可用时,为模块名称、类或函数的属性或文件名提供完成。 每个请求方法都显示一个带有现有名称的完成框。 (例外情况请参见下面的选项卡完成。)对于任何框,通过键入和删除字符来更改正在完成的名称和框中突出显示的项目; 通过点击 <span class="kbd kbd docutils literal notranslate">Up</span><span class="kbd kbd docutils literal notranslate">Down</span><span class="kbd kbd docutils literal notranslate">PageUp</span><span class="kbd kbd docutils literal notranslate">PageDown</span><span class="kbd kbd docutils literal notranslate">Home</span> End[X26X]钥匙; 并在框中单击一下。 使用 <span class="kbd kbd docutils literal notranslate">Escape</span><span class="kbd kbd docutils literal notranslate">Enter</span> 关闭框,然后双击 <span class="kbd kbd docutils literal notranslate">Tab</span> 键或在框外单击。 在框中双击选择并关闭。
names, attributes of classes or functions, or filenames. Each request
 
method displays a completion box with existing names. (See tab
 
completions below for an exception.) For any box, change the name
 
being completed and the item highlighted in the box by
 
typing and deleting characters; by hitting <span class="kbd kbd docutils literal notranslate">Up</span>, <span class="kbd kbd docutils literal notranslate">Down</span>,
 
<span class="kbd kbd docutils literal notranslate">PageUp</span>, <span class="kbd kbd docutils literal notranslate">PageDown</span>, <span class="kbd kbd docutils literal notranslate">Home</span>, and <span class="kbd kbd docutils literal notranslate">End</span> keys;
 
and by a single click within the box. Close the box with <span class="kbd kbd docutils literal notranslate">Escape</span>,
 
<span class="kbd kbd docutils literal notranslate">Enter</span>, and double <span class="kbd kbd docutils literal notranslate">Tab</span> keys or clicks outside the box.
 
A double click within the box selects and closes.
 
  
One way to open a box is to type a key character and wait for a
+
打开框的一种方法是键入一个关键字符并等待预定义的时间间隔。 默认为 2 秒; 在设置对话框中自定义它。 (要防止自动弹出,请将延迟设置为大量毫秒,例如 100000000。)对于导入的模块名称或类或函数属性,请键入“.”。 对于根目录中的文件名,在开始引号后立即键入 [[../os#os|os.sep]] [[../os#os|os.altsep]]。 (在 Windows 上,可以先指定驱动器。)通过键入目录名称和分隔符进入子目录。
predefined interval. This defaults to 2 seconds; customize it
 
in the settings dialog. (To prevent auto popups, set the delay to a
 
large number of milliseconds, such as 100000000.) For imported module
 
names or class or function attributes, type '.'.
 
For filenames in the root directory, type [[../os#os|<code>os.sep</code>]] or
 
[[../os#os|<code>os.altsep</code>]] immediately after an opening quote. (On Windows,
 
one can specify a drive first.) Move into subdirectories by typing a
 
directory name and a separator.
 
  
Instead of waiting, or after a box is closed, open a completion box
+
不要等待,或在框关闭后,立即使用“编辑”菜单上的“显示完成”打开完成框。 默认热键是 <span class="kbd kbd compound docutils literal notranslate">C-space</span>。 如果在打开框之前键入所需名称的前缀,则可以看到第一个匹配项或未命中。 结果与在显示框后输入前缀相同。 在引用完成当前目录而不是根目录中的文件名后显示完成。
immediately with Show Completions on the Edit menu. The default hot
 
key is <span class="kbd kbd docutils literal notranslate"><span class="kbd kbd docutils literal notranslate">C</span>-<span class="kbd kbd docutils literal notranslate">space</span></span>. If one types a prefix for the desired name
 
before opening the box, the first match or near miss is made visible.
 
The result is the same as if one enters a prefix
 
after the box is displayed. Show Completions after a quote completes
 
filenames in the current directory instead of a root directory.
 
  
Hitting <span class="kbd kbd docutils literal notranslate">Tab</span> after a prefix usually has the same effect as Show
+
在前缀后点击 <span class="kbd kbd docutils literal notranslate">Tab</span> 通常与 Show Completions 具有相同的效果。 (没有前缀,它会缩进。)但是,如果前缀只有一个匹配项,则该匹配项会立即添加到编辑器文本中,而无需打开框。
Completions. (With no prefix, it indents.) However, if there is only
 
one match to the prefix, that match is immediately added to the editor
 
text without opening a box.
 
  
Invoking 'Show Completions', or hitting <span class="kbd kbd docutils literal notranslate">Tab</span> after a prefix,
+
调用“Show Completions”,或在前缀之后、在字符串之外且没有前面的“.”时点击 <span class="kbd kbd docutils literal notranslate">Tab</span>。 打开一个包含关键字、内置名称和可用模块级名称的框。
outside of a string and without a preceding '.' opens a box with
 
keywords, builtin names, and available module-level names.
 
  
When editing code in an editor (as oppose to Shell), increase the
+
在编辑器中编辑代码时(与 Shell 相对),通过运行代码来增加可用的模块级名称,此后不要重新启动 Shell。 这在文件顶部添加导入后特别有用。 这也增加了可能的属性补全。
available module-level names by running your code
 
and not restarting the Shell thereafter. This is especially useful
 
after adding imports at the top of a file. This also increases
 
possible attribute completions.
 
  
Completion boxes intially exclude names beginning with '_' or, for
+
完成框最初排除以“_”开头的名称,或者对于模块,不包括在“__all__”中。 可以通过在打开框之前或之后在“.”之后键入“_”来访问隐藏名称。
modules, not included in '__all__'. The hidden names can be accessed
 
by typing '_' after '.', either before or after the box is opened.
 
  
  
第410行: 第347行:
 
<div id="calltips" class="section">
 
<div id="calltips" class="section">
  
<span id="id4"></span>
+
<span id="id6"></span>
=== Calltips ===
+
=== 提示 ===
  
A calltip is shown automatically when one types <span class="kbd kbd docutils literal notranslate">(</span> after the name
+
当在 ''accessible'' 函数的名称后键入 <span class="kbd kbd docutils literal notranslate">(</span> 时,会自动显示调用提示。 函数名表达式可以包含点和下标。 调用提示会一直保留,直到被单击、光标移出参数区域或键入 <span class="kbd kbd docutils literal notranslate">)</span>。 每当光标位于定义的参数部分时,选择菜单上的编辑和“显示调用提示”或输入其快捷方式以显示调用提示。
of an ''accessible'' function. A function name expression may include
 
dots and subscripts. A calltip remains until it is clicked, the cursor
 
is moved out of the argument area, or <span class="kbd kbd docutils literal notranslate">)</span> is typed. Whenever the
 
cursor is in the argument part of a definition, select Edit and &quot;Show
 
Call Tip&quot; on the menu or enter its shortcut to display a calltip.
 
  
The calltip consists of the function's signature and docstring up to
+
calltip 由函数的签名和文档字符串组成,直到后者的第一个空行或第五个非空行。 (某些内置函数缺少可访问的签名。)签名中的“/”或“*”表示前面或后面的参数仅按位置或名称(关键字)传递。 详细信息可能会发生变化。
the latter's first blank line or the fifth non-blank line. (Some builtin
 
functions lack an accessible signature.) A '/' or '*' in the signature
 
indicates that the preceding or following arguments are passed by
 
position or name (keyword) only. Details are subject to change.
 
  
In Shell, the accessible functions depends on what modules have been
+
Shell 中,可访问的函数取决于哪些模块已导入用户进程,包括 Idle 本身导入的模块,以及自上次重启以来已运行的定义。
imported into the user process, including those imported by Idle itself,
 
and which definitions have been run, all since the last restart.
 
  
For example, restart the Shell and enter <code>itertools.count(</code>. A calltip
+
例如重启Shell,输入<code>itertools.count(</code>。 出现调用提示是因为 Idle itertools 导入用户进程供其自己使用。 (这可能会改变。)输入 <code>turtle.write(</code> 并且什么也没有出现。 空闲本身不导入乌龟。 菜单项和快捷方式也没有任何作用。 输入 <code>import turtle</code>。 此后,<code>turtle.write(</code> 将显示一个提示。
appears because Idle imports itertools into the user process for its own
 
use. (This could change.) Enter <code>turtle.write(</code> and nothing appears.
 
Idle does not itself import turtle. The menu entry and shortcut also do
 
nothing. Enter <code>import turtle</code>. Thereafter, <code>turtle.write(</code>
 
will display a calltip.
 
  
In an editor, import statements have no effect until one runs the file.
+
在编辑器中,导入语句在运行文件之前无效。 人们可能希望在编写导入语句之后、在添加函数定义之后或在打开现有文件之后运行文件。
One might want to run a file after writing import statements, after
 
adding function definitions, or after opening an existing file.
 
  
  
第445行: 第364行:
 
<div id="code-context" class="section">
 
<div id="code-context" class="section">
  
<span id="id5"></span>
+
<span id="id7"></span>
=== Code Context ===
+
=== 代码上下文 ===
  
Within an editor window containing Python code, code context can be toggled
+
在包含 Python 代码的编辑器窗口中,可以切换代码上下文以显示或隐藏窗口顶部的窗格。 显示时,此窗格会冻结块代码的开头行,例如以 <code>class</code><code>def</code> <code>if</code> 关键字开头的行,否则这些代码会滚出视图。 窗格的大小将根据需要进行扩展和收缩,以显示所有当前级别的上下文,最多可达“配置空闲”对话框中定义的最大行数(默认为 15)。 如果当前没有上下文行并且该功能已打开,则将显示一个空行。 单击上下文窗格中的一行会将该行移动到编辑器的顶部。
in order to show or hide a pane at the top of the window. When shown, this
 
pane freezes the opening lines for block code, such as those beginning with
 
<code>class</code>, <code>def</code>, or <code>if</code> keywords, that would have otherwise scrolled
 
out of view. The size of the pane will be expanded and contracted as needed
 
to show the all current levels of context, up to the maximum number of
 
lines defined in the Configure IDLE dialog (which defaults to 15). If there
 
are no current context lines and the feature is toggled on, a single blank
 
line will display. Clicking on a line in the context pane will move that
 
line to the top of the editor.
 
  
The text and background colors for the context pane can be configured under
+
上下文窗格的文本和背景颜色可以在 Configure IDLE 对话框的 Highlights 选项卡下配置。
the Highlights tab in the Configure IDLE dialog.
 
  
  
第466行: 第375行:
 
<div id="python-shell-window" class="section">
 
<div id="python-shell-window" class="section">
  
=== Python Shell window ===
+
=== Python Shell 窗口 ===
  
With IDLE's Shell, one enters, edits, and recalls complete statements.
+
使用 IDLE 的 Shell,您可以输入、编辑和调用完整的语句。 大多数控制台和终端一次只能使用一条物理线路。
Most consoles and terminals only work with a single physical line at a time.
 
  
When one pastes code into Shell, it is not compiled and possibly executed
+
当将代码粘贴到 Shell 中时,直到点击 <span class="kbd kbd docutils literal notranslate">Return</span> 时,它才会被编译和执行。 可以先编辑粘贴的代码。 如果将多个语句粘贴到 Shell 中,那么当多条语句被编译为一条语句时,结果将是 [[../exceptions#SyntaxError|SyntaxError]]
until one hits <span class="kbd kbd docutils literal notranslate">Return</span>. One may edit pasted code first.
 
If one pastes more that one statement into Shell, the result will be a
 
[[../exceptions#SyntaxError|<code>SyntaxError</code>]] when multiple statements are compiled as if they were one.
 
  
The editing features described in previous subsections work when entering
+
以交互方式输入代码时,前面小节中描述的编辑功能会起作用。 IDLE Shell 窗口也会响应以下键。
code interactively. IDLE's Shell window also responds to the following keys.
 
  
 
<ul>
 
<ul>
<li><p><span class="kbd kbd docutils literal notranslate"><span class="kbd kbd docutils literal notranslate">C</span>-<span class="kbd kbd docutils literal notranslate">c</span></span> interrupts executing command</p></li>
+
<li><p><span class="kbd kbd compound docutils literal notranslate">Cc</span>中断执行命令</p></li>
<li><p><span class="kbd kbd docutils literal notranslate"><span class="kbd kbd docutils literal notranslate">C</span>-<span class="kbd kbd docutils literal notranslate">d</span></span> sends end-of-file; closes window if typed at a <code>&gt;&gt;&gt;</code> prompt</p></li>
+
<li><p><span class="kbd kbd compound docutils literal notranslate">Cd</span> 发送文件尾; 如果在 <code>&gt;&gt;&gt;</code> 提示符下键入,则关闭窗口</p></li>
<li><p><span class="kbd kbd docutils literal notranslate"><span class="kbd kbd docutils literal notranslate">Alt</span>-<span class="kbd kbd docutils literal notranslate">/</span></span> (Expand word) is also useful to reduce typing</p>
+
<li><p><span class="kbd kbd compound docutils literal notranslate">Alt-/</span>(扩展词)对于减少打字也很有用</p>
<p>Command history</p>
+
<p>命令历史</p>
 
<ul>
 
<ul>
<li><p><span class="kbd kbd docutils literal notranslate"><span class="kbd kbd docutils literal notranslate">Alt</span>-<span class="kbd kbd docutils literal notranslate">p</span></span> retrieves previous command matching what you have typed. On
+
<li><p><span class="kbd kbd compound docutils literal notranslate">Alt-p</span> 检索与您输入的内容匹配的先前命令。 在 macOS 上使用 <span class="kbd kbd compound docutils literal notranslate">Cp</span></p></li>
macOS use <span class="kbd kbd docutils literal notranslate"><span class="kbd kbd docutils literal notranslate">C</span>-<span class="kbd kbd docutils literal notranslate">p</span></span>.</p></li>
+
<li><p><span class="kbd kbd compound docutils literal notranslate">Alt-n</span> 检索下一个。 在 macOS 上使用 <span class="kbd kbd compound docutils literal notranslate">Cn</span></p></li>
<li><p><span class="kbd kbd docutils literal notranslate"><span class="kbd kbd docutils literal notranslate">Alt</span>-<span class="kbd kbd docutils literal notranslate">n</span></span> retrieves next. On macOS use <span class="kbd kbd docutils literal notranslate"><span class="kbd kbd docutils literal notranslate">C</span>-<span class="kbd kbd docutils literal notranslate">n</span></span>.</p></li>
+
<li><p><span class="kbd kbd docutils literal notranslate">Return</span> 在任何以前的命令上检索该命令</p></li></ul>
<li><p><span class="kbd kbd docutils literal notranslate">Return</span> while on any previous command retrieves that command</p></li></ul>
 
 
</li></ul>
 
</li></ul>
  
第495行: 第398行:
 
<div id="text-colors" class="section">
 
<div id="text-colors" class="section">
  
=== Text colors ===
+
=== 文字颜色 ===
  
Idle defaults to black on white text, but colors text with special meanings.
+
空闲在白色文本上默认为黑色,但为具有特殊含义的文本着色。 对于 shell,它们是 shell 输出、shell 错误、用户输出和用户错误。 对于 Python 代码,在 shell 提示符或编辑器中,这些是关键字、内置类和函数名称、<code>class</code> <code>def</code> 后面的名称、字符串和注释。 对于任何文本窗口,它们是光标(如果存在)、找到的文本(如果可能)和选定的文本。
For the shell, these are shell output, shell error, user output, and
 
user error. For Python code, at the shell prompt or in an editor, these are
 
keywords, builtin class and function names, names following <code>class</code> and
 
<code>def</code>, strings, and comments. For any text window, these are the cursor (when
 
present), found text (when possible), and selected text.
 
  
Text coloring is done in the background, so uncolorized text is occasionally
+
文本着色是在背景中完成的,因此偶尔会看到未着色的文本。 要更改配色方案,请使用配置空闲对话框突出显示选项卡。 编辑器中调试器断点行的标记以及弹出窗口和对话框中的文本不是用户可配置的。
visible. To change the color scheme, use the Configure IDLE dialog
 
Highlighting tab. The marking of debugger breakpoint lines in the editor and
 
text in popups and dialogs is not user-configurable.
 
  
  
第515行: 第410行:
 
<div id="startup-and-code-execution" class="section">
 
<div id="startup-and-code-execution" class="section">
  
== Startup and code execution ==
+
== 启动和代码执行 ==
  
Upon startup with the <code>-s</code> option, IDLE will execute the file referenced by
+
使用 <code>-s</code> 选项启动时,IDLE 将执行环境变量 <span id="index-5" class="target"></span><code>IDLESTARTUP</code> <span id="index-6" class="target"></span>[[../../using/cmdline#envvar-PYTHONSTARTUP|PYTHONSTARTUP]] 引用的文件。 IDLE 首先检查 <code>IDLESTARTUP</code>; 如果存在 <code>IDLESTARTUP</code>,则运行引用的文件。 如果 <code>IDLESTARTUP</code> 不存在,IDLE 检查 <code>PYTHONSTARTUP</code>。 这些环境变量引用的文件是存储 IDLE shell 中经常使用的函数或执行 import 语句以导入常用模块的方便位置。
the environment variables <span id="index-5" class="target"></span><code>IDLESTARTUP</code> or <span id="index-6" class="target"></span>[[../../using/cmdline#envvar-PYTHONSTARTUP|<code>PYTHONSTARTUP</code>]].
 
IDLE first checks for <code>IDLESTARTUP</code>; if <code>IDLESTARTUP</code> is present the file
 
referenced is run. If <code>IDLESTARTUP</code> is not present, IDLE checks for
 
<code>PYTHONSTARTUP</code>. Files referenced by these environment variables are
 
convenient places to store functions that are used frequently from the IDLE
 
shell, or for executing import statements to import common modules.
 
  
In addition, <code>Tk</code> also loads a startup file if it is present. Note that the
+
此外,<code>Tk</code> 还会加载启动文件(如果存在)。 请注意,Tk 文件是无条件加载的。 这个附加文件是 <code>.Idle.py</code> 并在用户的主目录中查找。 该文件中的语句将在 Tk 命名空间中执行,因此该文件对于从 IDLE Python shell 导入要使用的函数没有用处。
Tk file is loaded unconditionally. This additional file is <code>.Idle.py</code> and is
 
looked for in the user's home directory. Statements in this file will be
 
executed in the Tk namespace, so this file is not useful for importing
 
functions to be used from IDLE's Python shell.
 
  
 
<div id="command-line-usage" class="section">
 
<div id="command-line-usage" class="section">
  
=== Command line usage ===
+
=== 命令行使用 ===
  
 
<div class="highlight-none notranslate">
 
<div class="highlight-none notranslate">
第539行: 第424行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>idle.py [-c command] [-d] [-e] [-h] [-i] [-r file] [-s] [-t title] [-] [arg] ...
+
<pre class="none">idle.py [-c command] [-d] [-e] [-h] [-i] [-r file] [-s] [-t title] [-] [arg] ...
  
 
-c command  run command in the shell window
 
-c command  run command in the shell window
第554行: 第439行:
  
 
</div>
 
</div>
If there are arguments:
+
如果有争论:
  
* If <code>-</code>, <code>-c</code>, or <code>r</code> is used, all arguments are placed in <code>sys.argv[1:...]</code> and <code>sys.argv[0]</code> is set to <code>''</code>, <code>'-c'</code>, or <code>'-r'</code>. No editor window is opened, even if that is the default set in the Options dialog.
+
* 如果使用 <code>-</code><code>-c</code> <code>r</code>,则所有参数都放在 <code>sys.argv[1:...]</code> 中,并且 <code>sys.argv[0]</code> 设置为 [ X113X]、<code>'-c'</code> <code>'-r'</code>。 不会打开编辑器窗口,即使这是“选项”对话框中的默认设置。
* Otherwise, arguments are files opened for editing and <code>sys.argv</code> reflects the arguments passed to IDLE itself.
+
* 否则,参数是打开用于编辑的文件,<code>sys.argv</code> 反映传递给 IDLE 本身的参数。
  
  
第563行: 第448行:
 
<div id="startup-failure" class="section">
 
<div id="startup-failure" class="section">
  
=== Startup failure ===
+
=== 启动失败 ===
  
IDLE uses a socket to communicate between the IDLE GUI process and the user
+
IDLE 使用套接字在 IDLE GUI 进程和用户代码执行进程之间进行通信。 每当 Shell 启动或重新启动时,都必须建立连接。 (后者由表示“重新启动”的分隔线指示)。 如果用户进程无法连接到 GUI 进程,它通常会显示一个 <code>Tk</code> 错误框,并带有“无法连接”消息,将用户引导至此处。 然后它退出。
code execution process. A connection must be established whenever the Shell
 
starts or restarts. (The latter is indicated by a divider line that says
 
'RESTART'). If the user process fails to connect to the GUI process, it
 
displays a <code>Tk</code> error box with a 'cannot connect' message that directs the
 
user here. It then exits.
 
  
A common cause of failure is a user-written file with the same name as a
+
Unix 系统上的一个特定连接失败是由于系统网络设置中某处配置错误的伪装规则造成的。 当从终端启动 IDLE 时,会看到一条以 <code>** Invalid host:</code> 开头的消息。 有效值为 <code>127.0.0.1 (idlelib.rpc.LOCALHOST)</code>。 可以在一个终端窗口中使用 <code>tcpconnect -irv 127.0.0.1 6543</code> 进行诊断,而在另一个终端窗口中使用 <code>tcplisten &lt;same args&gt;</code> 进行诊断。
standard library module, such as ''random.py'' and ''tkinter.py''. When such a
 
file is located in the same directory as a file that is about to be run,
 
IDLE cannot import the stdlib file. The current fix is to rename the
 
user file.
 
  
Though less common than in the past, an antivirus or firewall program may
+
失败的常见原因是用户编写的文件与标准库模块同名,例如 ''random.py'' 和 ''tkinter.py''。 当此类文件与即将运行的文件位于同一目录中时,IDLE 无法导入 stdlib 文件。 当前的修复是重命名用户文件。
stop the connection. If the program cannot be taught to allow the
 
connection, then it must be turned off for IDLE to work. It is safe to
 
allow this internal connection because no data is visible on external
 
ports. A similar problem is a network mis-configuration that blocks
 
connections.
 
  
Python installation issues occasionally stop IDLE: multiple versions can
+
虽然不像过去那么常见,但防病毒程序或防火墙程序可能会停止连接。 如果无法教导程序允许连接,则必须关闭它才能使 IDLE 工作。 允许此内部连接是安全的,因为外部端口上没有数据可见。 一个类似的问题是阻止连接的网络错误配置。
clash, or a single installation might need admin access. If one undo the
 
clash, or cannot or does not want to run as admin, it might be easiest to
 
completely remove Python and start over.
 
  
A zombie pythonw.exe process could be a problem. On Windows, use Task
+
Python 安装问题有时会导致 IDLE 停止:多个版本可能会发生冲突,或者单个安装可能需要管理员访问权限。 如果有人撤消了冲突,或者不能或不想以管理员身份运行,那么完全删除 Python 并重新开始可能是最简单的。
Manager to check for one and stop it if there is. Sometimes a restart
 
initiated by a program crash or Keyboard Interrupt (control-C) may fail
 
to connect. Dismissing the error box or using Restart Shell on the Shell
 
menu may fix a temporary problem.
 
  
When IDLE first starts, it attempts to read user configuration files in
+
僵尸 pythonw.exe 进程可能是一个问题。 在 Windows 上,使用任务管理器来检查一个,如果有就停止它。 有时由程序崩溃或键盘中断 (control-C) 启动的重启可能无法连接。 关闭错误框或使用 Shell 菜单上的 Restart Shell 可能会解决临时问题。
<code>~/.idlerc/</code> (~ is one's home directory). If there is a problem, an error
 
message should be displayed. Leaving aside random disk glitches, this can
 
be prevented by never editing the files by hand. Instead, use the
 
configuration dialog, under Options. Once there is an error in a user
 
configuration file, the best solution may be to delete it and start over
 
with the settings dialog.
 
  
If IDLE quits with no message, and it was not started from a console, try
+
IDLE 第一次启动时,它会尝试读取 <code>~/.idlerc/</code>(~ 是一个人的主目录)中的用户配置文件。 如果出现问题,应显示错误消息。 撇开随机磁盘故障不谈,这可以通过从不手动编辑文件来防止。 相反,请使用选项下的配置对话框。 一旦用户配置文件出现错误,最好的解决方案可能是将其删除并从设置对话框重新开始。
starting it from a console or terminal (<code>python -m idlelib</code>) and see if
+
 
this results in an error message.
+
如果 IDLE 没有任何消息退出,并且它不是从控制台启动的,请尝试从控制台或终端 (<code>python -m idlelib</code>) 启动它,看看这是否会导致错误消息。
 +
 
 +
在 tcl/tk 早于 <code>8.6.11</code>(参见 <code>About IDLE</code>)的基于 Unix 的系统上,某些字体的某些字符会导致 tk 失败并向终端发送消息。 如果启动 IDLE 以编辑具有此类字符的文件或稍后输入此类字符,则可能会发生这种情况。 如果无法升级 tcl/tk,则重新配置 IDLE 以使用效果更好的字体。
  
  
第612行: 第472行:
 
<div id="running-user-code" class="section">
 
<div id="running-user-code" class="section">
  
=== Running user code ===
+
=== 运行用户代码 ===
 +
 
 +
除了极少数例外,使用 IDLE 执行 Python 代码的结果与通过默认方法直接在文本模式系统控制台或终端窗口中使用 Python 执行相同代码的结果相同。 但是,不同的界面和操作偶尔会影响可见的结果。 例如,<code>sys.modules</code> 以更多条目开头,而 <code>threading.active_count()</code> 返回 2 而不是 1。
  
With rare exceptions, the result of executing Python code with IDLE is
+
默认情况下,IDLE 在单独的操作系统进程中运行用户代码,而不是在运行 shell 和编辑器的用户界面进程中运行。 在执行过程中,它将<code>sys.stdin</code>、<code>sys.stdout</code>和<code>sys.stderr</code>替换为从Shell窗口获取输入和向Shell窗口发送输出的对象。 存储在 <code>sys.__stdin__</code><code>sys.__stdout__</code> 和 <code>sys.__stderr__</code> 中的原始值没有被触摸,但可能是 <code>None</code>。
intended to be the same as executing the same code by the default method,
 
directly with Python in a text-mode system console or terminal window.
 
However, the different interface and operation occasionally affect
 
visible results. For instance, <code>sys.modules</code> starts with more entries,
 
and <code>threading.activeCount()</code> returns 2 instead of 1.
 
  
By default, IDLE runs user code in a separate OS process rather than in
+
将打印输出从一个进程发送到另一个进程中的文本小部件比打印到同一进程中的系统终端慢。 这在打印多个参数时最有效,因为每个参数的字符串、每个分隔符、换行符都是单独发送的。 对于开发来说,这通常不是问题,但是如果想在 IDLE 中更快地打印,请格式化并将想要显示的所有内容连接在一起,然后打印单个字符串。 格式字符串和 [[../stdtypes#str|str.join()]] 都可以帮助组合字段和行。
the user interface process that runs the shell and editor. In the execution
 
process, it replaces <code>sys.stdin</code>, <code>sys.stdout</code>, and <code>sys.stderr</code>
 
with objects that get input from and send output to the Shell window.
 
The original values stored in <code>sys.__stdin__</code>, <code>sys.__stdout__</code>, and
 
<code>sys.__stderr__</code> are not touched, but may be <code>None</code>.
 
  
When Shell has the focus, it controls the keyboard and screen. This is
+
IDLE 的标准流替换不会被执行过程中创建的子进程继承,无论是直接由用户代码还是由多处理等模块。 如果此类子进程使用来自 sys.stdin 或 <code>print</code> 或 <code>write</code> 的 <code>input</code> 到 sys.stdout 或 sys.stderr,则应在命令行窗口中启动 IDLE。 然后,辅助子进程将附加到该窗口以进行输入和输出。
normally transparent, but functions that directly access the keyboard
 
and screen will not work. These include system-specific functions that
 
determine whether a key has been pressed and if so, which.
 
  
IDLE's standard stream replacements are not inherited by subprocesses
+
如果 <code>sys</code> 由用户代码重置,例如使用 <code>importlib.reload(sys)</code>,IDLE 的更改将丢失并且从键盘输入和输出到屏幕将无法正常工作。
created in the execution process, whether directly by user code or by modules
 
such as multiprocessing. If such subprocess use <code>input</code> from sys.stdin
 
or <code>print</code> or <code>write</code> to sys.stdout or sys.stderr,
 
IDLE should be started in a command line window. The secondary subprocess
 
will then be attached to that window for input and output.
 
  
The IDLE code running in the execution process adds frames to the call stack
+
当 Shell 获得焦点时,它控制键盘和屏幕。 这通常是透明的,但直接访问键盘和屏幕的功能将不起作用。 其中包括系统特定的功能,用于确定是否按下了某个键,如果按下了,按下了哪个键。
that would not be there otherwise. IDLE wraps <code>sys.getrecursionlimit</code> and
 
<code>sys.setrecursionlimit</code> to reduce the effect of the additional stack frames.
 
  
If <code>sys</code> is reset by user code, such as with <code>importlib.reload(sys)</code>,
+
在执行过程中运行的 IDLE 代码将帧添加到调用堆栈中,否则这些帧将不存在。 IDLE 包装 <code>sys.getrecursionlimit</code> <code>sys.setrecursionlimit</code> 以减少额外堆栈帧的影响。
IDLE's changes are lost and input from the keyboard and output to the screen
 
will not work correctly.
 
  
When user code raises SystemExit either directly or by calling sys.exit, IDLE
+
当用户代码直接或通过调用 sys.exit 引发 SystemExit 时,IDLE 将返回到 Shell 提示符而不是退出。
returns to a Shell prompt instead of exiting.
 
  
  
第655行: 第494行:
 
<div id="user-output-in-shell" class="section">
 
<div id="user-output-in-shell" class="section">
  
=== User output in Shell ===
+
=== Shell 中的用户输出 ===
  
When a program outputs text, the result is determined by the
+
当程序输出文本时,结果由相应的输出设备决定。 IDLE执行用户代码时,<code>sys.stdout</code><code>sys.stderr</code>连接到IDLE的Shell的显示区域。 它的一些功能是从底层的 Tk 文本小部件继承而来的。 其他是程序化的添加。 在重要的地方,壳牌专为开发而不是生产运行而设计。
corresponding output device. When IDLE executes user code, <code>sys.stdout</code>
 
and <code>sys.stderr</code> are connected to the display area of IDLE's Shell. Some of
 
its features are inherited from the underlying Tk Text widget. Others
 
are programmed additions. Where it matters, Shell is designed for development
 
rather than production runs.
 
  
For instance, Shell never throws away output. A program that sends unlimited
+
例如,Shell 从不丢弃输出。 向 Shell 发送无限输出的程序最终会填满内存,从而导致内存错误。 相比之下,一些系统文本窗口只保留最后 n 行输出。 例如,Windows 控制台保留用户可设置的 1 9999 行,默认值为 300。
output to Shell will eventually fill memory, resulting in a memory error.
 
In contrast, some system text windows only keep the last n lines of output.
 
A Windows console, for instance, keeps a user-settable 1 to 9999 lines,
 
with 300 the default.
 
  
A Tk Text widget, and hence IDLE's Shell, displays characters (codepoints) in
+
Tk Text 小部件,以及 IDLE 的 Shell,在 Unicode 的 BMP(基本多语言平面)子集中显示字符(代码点)。 哪些字符使用适当的字形显示,哪些使用替换框取决于操作系统和安装的字体。 制表符导致以下文本在下一个制表位之后开始。 (它们每 8 个“字符”出现一次)。 换行符导致以下文本出现在新行上。 其他控制字符将被忽略或显示为空格、框或其他内容,具体取决于操作系统和字体。 (使用箭头键在这样的输出中移动文本光标可能会出现一些令人惊讶的间距行为。)
the BMP (Basic Multilingual Plane) subset of Unicode. Which characters are
 
displayed with a proper glyph and which with a replacement box depends on the
 
operating system and installed fonts. Tab characters cause the following text
 
to begin after the next tab stop. (They occur every 8 'characters'). Newline
 
characters cause following text to appear on a new line. Other control
 
characters are ignored or displayed as a space, box, or something else,
 
depending on the operating system and font. (Moving the text cursor through
 
such output with arrow keys may exhibit some surprising spacing behavior.)
 
  
 
<div class="highlight-python3 notranslate">
 
<div class="highlight-python3 notranslate">
第684行: 第506行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>&gt;&gt;&gt; s = 'a\tb\a&lt;\x02&gt;&lt;\r&gt;\bc\nd'  # Enter 22 chars.
+
<syntaxhighlight lang="python3">>>> s = 'a\tb\a<\x02><\r>\bc\nd'  # Enter 22 chars.
&gt;&gt;&gt; len(s)
+
>>> len(s)
 
14
 
14
&gt;&gt;&gt; s  # Display repr(s)
+
>>> s  # Display repr(s)
'a\tb\x07&lt;\x02&gt;&lt;\r&gt;\x08c\nd'
+
'a\tb\x07<\x02><\r>\x08c\nd'
&gt;&gt;&gt; print(s, end='')  # Display s as is.
+
>>> print(s, end='')  # Display s as is.
# Result varies by OS and font.  Try it.</pre>
+
# Result varies by OS and font.  Try it.</syntaxhighlight>
  
 
</div>
 
</div>
  
 
</div>
 
</div>
The <code>repr</code> function is used for interactive echo of expression
+
<code>repr</code> 函数用于表达式值的交互式回显。 它返回输入字符串的更改版本,其中控制代码、一些 BMP 代码点和所有非 BMP 代码点都替换为转义代码。 如上所述,它允许人们识别字符串中的字符,而不管它们如何显示。
values. It returns an altered version of the input string in which
 
control codes, some BMP codepoints, and all non-BMP codepoints are
 
replaced with escape codes. As demonstrated above, it allows one to
 
identify the characters in a string, regardless of how they are displayed.
 
  
Normal and error output are generally kept separate (on separate lines)
+
正常和错误输出通常与代码输入和彼此分开(在单独的行上)。 它们每个都有不同的高亮颜色。
from code input and each other. They each get different highlight colors.
 
  
For SyntaxError tracebacks, the normal '^' marking where the error was
+
对于 SyntaxError 回溯,检测到错误的正常 '^' 标记被替换为使用错误突出显示的文本着色。 当从文件运行的代码导致其他异常时,可以右键单击回溯行以跳转到空闲编辑器中的相应行。 如有必要,将打开该文件。
detected is replaced by coloring the text with an error highlight.
 
When code run from a file causes other exceptions, one may right click
 
on a traceback line to jump to the corresponding line in an IDLE editor.
 
The file will be opened if necessary.
 
  
Shell has a special facility for squeezing output lines down to a
+
Shell 具有将输出行压缩为“压缩文本”标签的特殊工具。 对于 N 行(默认为 N = 50)的输出,这是自动完成的。 N 可以在 Settings 对话框的 General 页面的 PyShell 部分中更改。 可以通过右键单击输出来压缩行数较少的输出。 这可能是足够长的有用行以减慢滚动速度。
'Squeezed text' label. This is done automatically
 
for output over N lines (N = 50 by default).
 
N can be changed in the PyShell section of the General
 
page of the Settings dialog. Output with fewer lines can be squeezed by
 
right clicking on the output. This can be useful lines long enough to slow
 
down scrolling.
 
  
Squeezed output is expanded in place by double-clicking the label.
+
通过双击标签将压缩的输出扩展到位。 也可以通过右键单击标签将其发送到剪贴板或单独的视图窗口。
It can also be sent to the clipboard or a separate view window by
 
right-clicking the label.
 
  
  
第726行: 第531行:
 
<div id="developing-tkinter-applications" class="section">
 
<div id="developing-tkinter-applications" class="section">
  
=== Developing tkinter applications ===
+
=== 开发 tkinter 应用程序 ===
  
IDLE is intentionally different from standard Python in order to
+
IDLE 有意与标准 Python 不同,以促进 tkinter 程序的开发。 在标准 Python 中输入 <code>import tkinter as tk; root = tk.Tk()</code> 没有任何显示。 在 IDLE 中输入相同的内容并出现一个 tk 窗口。 在标准 Python 中,还必须输入 <code>root.update()</code> 才能看到窗口。 IDLE 在后台做同样的事情,大约每秒 20 次,大约每 50 毫秒一次。 接下来输入<code>b = tk.Button(root, text='button'); b.pack()</code>。 同样,在进入 <code>root.update()</code> 之前,标准 Python 中没有任何明显变化。
facilitate development of tkinter programs. Enter <code>import tkinter as tk; root = tk.Tk()</code> in standard Python and nothing appears. Enter the same
 
in IDLE and a tk window appears. In standard Python, one must also enter
 
<code>root.update()</code> to see the window. IDLE does the equivalent in the
 
background, about 20 times a second, which is about every 50 milliseconds.
 
Next enter <code>b = tk.Button(root, text='button'); b.pack()</code>. Again,
 
nothing visibly changes in standard Python until one enters <code>root.update()</code>.
 
  
Most tkinter programs run <code>root.mainloop()</code>, which usually does not
+
大多数 tkinter 程序运行 <code>root.mainloop()</code>,通常在 tk 应用程序被销毁之前不会返回。 如果程序使用 <code>python -i</code> 或从 IDLE 编辑器运行,则在 <code>mainloop()</code> 返回之前不会出现 <code>&gt;&gt;&gt;</code> shell 提示,此时没有任何可交互的内容。
return until the tk app is destroyed. If the program is run with
 
<code>python -i</code> or from an IDLE editor, a <code>&gt;&gt;&gt;</code> shell prompt does not
 
appear until <code>mainloop()</code> returns, at which time there is nothing left
 
to interact with.
 
  
When running a tkinter program from an IDLE editor, one can comment out
+
从 IDLE 编辑器运行 tkinter 程序时,可以注释掉 mainloop 调用。 然后立即得到一个 shell 提示,并可以与实时应用程序进行交互。 只需要记住在标准 Python 中运行时重新启用 mainloop 调用。
the mainloop call. One then gets a shell prompt immediately and can
 
interact with the live application. One just has to remember to
 
re-enable the mainloop call when running in standard Python.
 
  
  
第751行: 第543行:
 
<div id="running-without-a-subprocess" class="section">
 
<div id="running-without-a-subprocess" class="section">
  
=== Running without a subprocess ===
+
=== 在没有子进程的情况下运行 ===
  
By default, IDLE executes user code in a separate subprocess via a socket,
+
默认情况下,IDLE 通过使用内部环回接口的套接字在单独的子进程中执行用户代码。 此连接在外部不可见,并且不会向 Internet 发送或从 Internet 接收任何数据。 如果防火墙软件仍然抱怨,您可以忽略它。
which uses the internal loopback interface. This connection is not
 
externally visible and no data is sent to or received from the Internet.
 
If firewall software complains anyway, you can ignore it.
 
  
If the attempt to make the socket connection fails, Idle will notify you.
+
如果尝试建立套接字连接失败,Idle 会通知您。 此类故障有时是暂时的,但如果持续存在,则问题可能是防火墙阻止了连接或特定系统的错误配置。 在问题解决之前,可以使用 -n 命令行开关运行 Idle。
Such failures are sometimes transient, but if persistent, the problem
 
may be either a firewall blocking the connection or misconfiguration of
 
a particular system. Until the problem is fixed, one can run Idle with
 
the -n command line switch.
 
  
If IDLE is started with the -n command line switch it will run in a
+
如果 IDLE 使用 -n 命令行开关启动,它将在单个进程中运行,并且不会创建运行 RPC Python 执行服务器的子进程。 如果 Python 无法在您的平台上创建子进程或 RPC 套接字接口,这会很有用。 但是,在这种模式下,用户代码与 IDLE 本身并不隔离。 此外,选择运行/运行模块 (F5) 时不会重新启动环境。 如果您的代码已被修改,您必须 reload() 受影响的模块并重新导入任何特定项目(例如 from foo import baz) 如果更改生效。 由于这些原因,最好尽可能使用默认子进程运行 IDLE。
single process and will not create the subprocess which runs the RPC
 
Python execution server. This can be useful if Python cannot create
 
the subprocess or the RPC socket interface on your platform. However,
 
in this mode user code is not isolated from IDLE itself. Also, the
 
environment is not restarted when Run/Run Module (F5) is selected. If
 
your code has been modified, you must reload() the affected modules and
 
re-import any specific items (e.g. from foo import baz) if the changes
 
are to take effect. For these reasons, it is preferable to run IDLE
 
with the default subprocess if at all possible.
 
  
 
<div class="deprecated">
 
<div class="deprecated">
  
<span class="versionmodified deprecated">3.4 版后已移除.</span>
+
<span class="versionmodified deprecated">3.4 版起已弃用。</span>
  
  
第787行: 第563行:
 
<div id="help-and-preferences" class="section">
 
<div id="help-and-preferences" class="section">
  
== Help and preferences ==
+
== 帮助和偏好 ==
  
 
<div id="help-sources" class="section">
 
<div id="help-sources" class="section">
  
<span id="id6"></span>
+
<span id="id8"></span>
=== Help sources ===
+
=== 帮助来源 ===
  
Help menu entry &quot;IDLE Help&quot; displays a formatted html version of the
+
帮助菜单条目“空闲帮助”显示了库参考中空闲章节的格式化 html 版本。 结果,在只读 tkinter 文本窗口中,与人们在 Web 浏览器中看到的非常接近。 使用鼠标滚轮、滚动条或按住上下箭头键浏览文本。 或者单击 TOC(目录)按钮并在打开的框中选择一个节标题。
IDLE chapter of the Library Reference. The result, in a read-only
 
tkinter text window, is close to what one sees in a web browser.
 
Navigate through the text with a mousewheel,
 
the scrollbar, or up and down arrow keys held down.
 
Or click the TOC (Table of Contents) button and select a section
 
header in the opened box.
 
  
Help menu entry &quot;Python Docs&quot; opens the extensive sources of help,
+
帮助菜单条目“Python Docs”打开了广泛的帮助来源,包括教程,可从 <code>docs.python.org/x.y</code> 获得,其中“x.y”是当前运行的 Python 版本。 如果您的系统有文档的离线副本(这可能是一个安装选项),则会打开该副本。
including tutorials, available at <code>docs.python.org/x.y</code>, where 'x.y'
 
is the currently running Python version. If your system
 
has an off-line copy of the docs (this may be an installation option),
 
that will be opened instead.
 
  
Selected URLs can be added or removed from the help menu at any time using the
+
可以随时使用“配置空闲”对话框的“常规”选项卡从帮助菜单中添加或删除选定的 URL。
General tab of the Configure IDLE dialog.
 
  
  
第816行: 第581行:
  
 
<span id="preferences"></span>
 
<span id="preferences"></span>
=== Setting preferences ===
+
=== 设置首选项 ===
  
The font preferences, highlighting, keys, and general preferences can be
+
可以通过“选项”菜单上的“配置空闲”更改字体首选项、突出显示、键和一般首选项。 非默认用户设置保存在用户主目录的 <code>.idlerc</code> 目录中。 通过编辑或删除<code>.idlerc</code>中的一个或多个文件来解决由不良用户配置文件引起的问题。
changed via Configure IDLE on the Option menu.
 
Non-default user settings are saved in a <code>.idlerc</code> directory in the user's
 
home directory. Problems caused by bad user configuration files are solved
 
by editing or deleting one or more of the files in <code>.idlerc</code>.
 
  
On the Font tab, see the text sample for the effect of font face and size
+
在“字体”选项卡上,请参阅有关字体和大小对多种语言的多个字符的影响的文本示例。 编辑示例以添加个人感兴趣的其他角色。 使用示例选择等宽字体。 如果特定字符在 Shell 或编辑器中出现问题,请将它们添加到示例的顶部并尝试先更改大小,然后再更改字体。
on multiple characters in multiple languages. Edit the sample to add
 
other characters of personal interest. Use the sample to select
 
monospaced fonts. If particular characters have problems in Shell or an
 
editor, add them to the top of the sample and try changing first size
 
and then font.
 
  
On the Highlights and Keys tab, select a built-in or custom color theme
+
在突出显示和键选项卡上,选择内置或自定义颜色主题和键集。 要在较旧的 IDLE 中使用较新的内置颜色主题或键集,请将其另存为新的自定义主题或键集,以便较旧的 IDLE 可以访问它。
and key set. To use a newer built-in color theme or key set with older
 
IDLEs, save it as a new custom theme or key set and it well be accessible
 
to older IDLEs.
 
  
  
第840行: 第593行:
 
<div id="idle-on-macos" class="section">
 
<div id="idle-on-macos" class="section">
  
=== IDLE on macOS ===
+
=== macOS 上空闲 ===
  
Under System Preferences: Dock, one can set &quot;Prefer tabs when opening
+
System Preferences: Dock 下,可以将“打开文档时首选选项卡”设置为“始终”。 此设置与 IDLE 使用的 tk/tkinter GUI 框架不兼容,并且它破坏了一些 IDLE 功能。
documents&quot; to &quot;Always&quot;. This setting is not compatible with the tk/tkinter
 
GUI framework used by IDLE, and it breaks a few IDLE features.
 
  
  
第850行: 第601行:
 
<div id="extensions" class="section">
 
<div id="extensions" class="section">
  
=== Extensions ===
+
=== 扩展 ===
  
IDLE contains an extension facility. Preferences for extensions can be
+
IDLE 包含一个扩展工具。 可以使用首选项对话框的扩展选项卡更改扩展首选项。 有关详细信息,请参阅 idlelib 目录中 config-extensions.def 的开头部分。 当前唯一的默认扩展名是 zzdummy,一个示例也用于测试。
changed with the Extensions tab of the preferences dialog. See the
 
beginning of config-extensions.def in the idlelib directory for further
 
information. The only current default extension is zzdummy, an example
 
also used for testing.
 
  
  
第862行: 第609行:
  
 
</div>
 
</div>
 +
 +
</div>
 +
<div class="clearer">
 +
 +
  
 
</div>
 
</div>
  
[[Category:Python 3.9 中文文档]]
+
[[Category:Python 3.9 文档]]

2021年10月31日 (日) 04:52的最新版本

空闲

源代码: :source:`库/空闲库/`



IDLE 是 Python 的集成开发和学习环境。

IDLE具有以下特点:

  • 100% 纯 Python 编码,使用 tkinter GUI 工具包
  • 跨平台:在 Windows、Unix 和 macOS 上的工作方式大致相同
  • 带有代码输入、输出和错误消息着色的 Python shell 窗口(交互式解释器)
  • 具有多个撤销、Python 着色、智能缩进、调用提示、自动完成和其他功能的多窗口文本编辑器
  • 在任何窗口中搜索,在编辑器窗口中替换,并搜索多个文件 (grep)
  • 具有持久断点、步进和查看全局和本地命名空间的调试器
  • 配置、浏览器和其他对话框

编辑和导航

编辑器窗口

IDLE 可能会在启动时打开编辑器窗口,具体取决于设置和您启动 IDLE 的方式。 此后,使用文件菜单。 给定文件只能有一个打开的编辑器窗口。

标题栏包含文件名、完整路径以及运行窗口的 Python 和 IDLE 版本。 状态栏包含行号 ('Ln') 和列号 ('Col')。 行号从 1 开始; 列号为 0。

IDLE 假定具有已知 .py* 扩展名的文件包含 Python 代码,而其他文件不包含。 使用运行菜单运行 Python 代码。


键绑定

在本节中,“C”指的是 Windows 和 Unix 上的 Control 键以及 macOS 上的 Command 键。

  • Backspace 向左删除; Del 向右删除

  • C-Backspace 删除左字; C-Del删除右边的字

  • 方向键和 Page Up/Page Down 左右移动

  • C-LeftArrowC-RightArrow 按单词移动

  • Home/End转到行首/行尾

  • C-Home/C-End 转到文件的开头/结尾

  • 一些有用的 Emacs 绑定是从 Tcl/Tk 继承的:

    • Ca 行首

    • Ce 行尾

    • Ck 终止线(但不将其放入剪贴板)

    • Cl 插入点周围的中心窗口

    • Cb 后退一个字符而不删除(通常您也可以使用光标键进行此操作)

    • Cf 向前移动一个字符而不删除(通常您也可以使用光标键进行此操作)

    • Cp 上一行(通常也可以使用光标键)

    • Cd 删除下一个字符


标准键绑定(如 Cc 复制和 Cv 粘贴)可能有效。 在“配置空闲”对话框中选择键绑定。


自动缩进

在块开始语句之后,下一行缩进 4 个空格(在 Python Shell 窗口中缩进一个选项卡)。 在某些关键字(break、return 等)之后,下一行被缩进。 在前导缩进中,Backspace 最多删除 4 个空格(如果存在)。 Tab 插入空格(在 Python Shell 窗口中的一个选项卡),数量取决于缩进宽度。 目前,由于 Tcl/Tk 的限制,制表符被限制为四个空格。

另请参阅 格式菜单 上的缩进/缩进区域命令。


完成

在请求和可用时,为模块名称、类或函数的属性或文件名提供完成。 每个请求方法都显示一个带有现有名称的完成框。 (例外情况请参见下面的选项卡完成。)对于任何框,通过键入和删除字符来更改正在完成的名称和框中突出显示的项目; 通过点击 UpDownPageUpPageDownHome 和 End[X26X]钥匙; 并在框中单击一下。 使用 EscapeEnter 关闭框,然后双击 Tab 键或在框外单击。 在框中双击选择并关闭。

打开框的一种方法是键入一个关键字符并等待预定义的时间间隔。 默认为 2 秒; 在设置对话框中自定义它。 (要防止自动弹出,请将延迟设置为大量毫秒,例如 100000000。)对于导入的模块名称或类或函数属性,请键入“.”。 对于根目录中的文件名,在开始引号后立即键入 os.sepos.altsep。 (在 Windows 上,可以先指定驱动器。)通过键入目录名称和分隔符进入子目录。

不要等待,或在框关闭后,立即使用“编辑”菜单上的“显示完成”打开完成框。 默认热键是 C-space。 如果在打开框之前键入所需名称的前缀,则可以看到第一个匹配项或未命中。 结果与在显示框后输入前缀相同。 在引用完成当前目录而不是根目录中的文件名后显示完成。

在前缀后点击 Tab 通常与 Show Completions 具有相同的效果。 (没有前缀,它会缩进。)但是,如果前缀只有一个匹配项,则该匹配项会立即添加到编辑器文本中,而无需打开框。

调用“Show Completions”,或在前缀之后、在字符串之外且没有前面的“.”时点击 Tab。 打开一个包含关键字、内置名称和可用模块级名称的框。

在编辑器中编辑代码时(与 Shell 相对),通过运行代码来增加可用的模块级名称,此后不要重新启动 Shell。 这在文件顶部添加导入后特别有用。 这也增加了可能的属性补全。

完成框最初排除以“_”开头的名称,或者对于模块,不包括在“__all__”中。 可以通过在打开框之前或之后在“.”之后键入“_”来访问隐藏名称。


提示

当在 accessible 函数的名称后键入 ( 时,会自动显示调用提示。 函数名表达式可以包含点和下标。 调用提示会一直保留,直到被单击、光标移出参数区域或键入 )。 每当光标位于定义的参数部分时,选择菜单上的编辑和“显示调用提示”或输入其快捷方式以显示调用提示。

calltip 由函数的签名和文档字符串组成,直到后者的第一个空行或第五个非空行。 (某些内置函数缺少可访问的签名。)签名中的“/”或“*”表示前面或后面的参数仅按位置或名称(关键字)传递。 详细信息可能会发生变化。

在 Shell 中,可访问的函数取决于哪些模块已导入用户进程,包括 Idle 本身导入的模块,以及自上次重启以来已运行的定义。

例如重启Shell,输入itertools.count(。 出现调用提示是因为 Idle 将 itertools 导入用户进程供其自己使用。 (这可能会改变。)输入 turtle.write( 并且什么也没有出现。 空闲本身不导入乌龟。 菜单项和快捷方式也没有任何作用。 输入 import turtle。 此后,turtle.write( 将显示一个提示。

在编辑器中,导入语句在运行文件之前无效。 人们可能希望在编写导入语句之后、在添加函数定义之后或在打开现有文件之后运行文件。


代码上下文

在包含 Python 代码的编辑器窗口中,可以切换代码上下文以显示或隐藏窗口顶部的窗格。 显示时,此窗格会冻结块代码的开头行,例如以 classdefif 关键字开头的行,否则这些代码会滚出视图。 窗格的大小将根据需要进行扩展和收缩,以显示所有当前级别的上下文,最多可达“配置空闲”对话框中定义的最大行数(默认为 15)。 如果当前没有上下文行并且该功能已打开,则将显示一个空行。 单击上下文窗格中的一行会将该行移动到编辑器的顶部。

上下文窗格的文本和背景颜色可以在 Configure IDLE 对话框的 Highlights 选项卡下配置。


Python Shell 窗口

使用 IDLE 的 Shell,您可以输入、编辑和调用完整的语句。 大多数控制台和终端一次只能使用一条物理线路。

当将代码粘贴到 Shell 中时,直到点击 Return 时,它才会被编译和执行。 可以先编辑粘贴的代码。 如果将多个语句粘贴到 Shell 中,那么当多条语句被编译为一条语句时,结果将是 SyntaxError

以交互方式输入代码时,前面小节中描述的编辑功能会起作用。 IDLE 的 Shell 窗口也会响应以下键。

  • Cc中断执行命令

  • Cd 发送文件尾; 如果在 >>> 提示符下键入,则关闭窗口

  • Alt-/(扩展词)对于减少打字也很有用

    命令历史

    • Alt-p 检索与您输入的内容匹配的先前命令。 在 macOS 上使用 Cp

    • Alt-n 检索下一个。 在 macOS 上使用 Cn

    • Return 在任何以前的命令上检索该命令


文字颜色

空闲在白色文本上默认为黑色,但为具有特殊含义的文本着色。 对于 shell,它们是 shell 输出、shell 错误、用户输出和用户错误。 对于 Python 代码,在 shell 提示符或编辑器中,这些是关键字、内置类和函数名称、classdef 后面的名称、字符串和注释。 对于任何文本窗口,它们是光标(如果存在)、找到的文本(如果可能)和选定的文本。

文本着色是在背景中完成的,因此偶尔会看到未着色的文本。 要更改配色方案,请使用配置空闲对话框突出显示选项卡。 编辑器中调试器断点行的标记以及弹出窗口和对话框中的文本不是用户可配置的。


启动和代码执行

使用 -s 选项启动时,IDLE 将执行环境变量 IDLESTARTUPPYTHONSTARTUP 引用的文件。 IDLE 首先检查 IDLESTARTUP; 如果存在 IDLESTARTUP,则运行引用的文件。 如果 IDLESTARTUP 不存在,IDLE 检查 PYTHONSTARTUP。 这些环境变量引用的文件是存储 IDLE shell 中经常使用的函数或执行 import 语句以导入常用模块的方便位置。

此外,Tk 还会加载启动文件(如果存在)。 请注意,Tk 文件是无条件加载的。 这个附加文件是 .Idle.py 并在用户的主目录中查找。 该文件中的语句将在 Tk 命名空间中执行,因此该文件对于从 IDLE 的 Python shell 导入要使用的函数没有用处。

命令行使用

idle.py [-c command] [-d] [-e] [-h] [-i] [-r file] [-s] [-t title] [-] [arg] ...

-c command  run command in the shell window
-d          enable debugger and open shell window
-e          open editor window
-h          print help message with legal combinations and exit
-i          open shell window
-r file     run file in shell window
-s          run $IDLESTARTUP or $PYTHONSTARTUP first, in shell window
-t title    set title of shell window
-           run stdin in shell (- must be last option before args)

如果有争论:

  • 如果使用 --cr,则所有参数都放在 sys.argv[1:...] 中,并且 sys.argv[0] 设置为 [ X113X]、'-c''-r'。 不会打开编辑器窗口,即使这是“选项”对话框中的默认设置。
  • 否则,参数是打开用于编辑的文件,sys.argv 反映传递给 IDLE 本身的参数。


启动失败

IDLE 使用套接字在 IDLE GUI 进程和用户代码执行进程之间进行通信。 每当 Shell 启动或重新启动时,都必须建立连接。 (后者由表示“重新启动”的分隔线指示)。 如果用户进程无法连接到 GUI 进程,它通常会显示一个 Tk 错误框,并带有“无法连接”消息,将用户引导至此处。 然后它退出。

Unix 系统上的一个特定连接失败是由于系统网络设置中某处配置错误的伪装规则造成的。 当从终端启动 IDLE 时,会看到一条以 ** Invalid host: 开头的消息。 有效值为 127.0.0.1 (idlelib.rpc.LOCALHOST)。 可以在一个终端窗口中使用 tcpconnect -irv 127.0.0.1 6543 进行诊断,而在另一个终端窗口中使用 tcplisten <same args> 进行诊断。

失败的常见原因是用户编写的文件与标准库模块同名,例如 random.pytkinter.py。 当此类文件与即将运行的文件位于同一目录中时,IDLE 无法导入 stdlib 文件。 当前的修复是重命名用户文件。

虽然不像过去那么常见,但防病毒程序或防火墙程序可能会停止连接。 如果无法教导程序允许连接,则必须关闭它才能使 IDLE 工作。 允许此内部连接是安全的,因为外部端口上没有数据可见。 一个类似的问题是阻止连接的网络错误配置。

Python 安装问题有时会导致 IDLE 停止:多个版本可能会发生冲突,或者单个安装可能需要管理员访问权限。 如果有人撤消了冲突,或者不能或不想以管理员身份运行,那么完全删除 Python 并重新开始可能是最简单的。

僵尸 pythonw.exe 进程可能是一个问题。 在 Windows 上,使用任务管理器来检查一个,如果有就停止它。 有时由程序崩溃或键盘中断 (control-C) 启动的重启可能无法连接。 关闭错误框或使用 Shell 菜单上的 Restart Shell 可能会解决临时问题。

当 IDLE 第一次启动时,它会尝试读取 ~/.idlerc/(~ 是一个人的主目录)中的用户配置文件。 如果出现问题,应显示错误消息。 撇开随机磁盘故障不谈,这可以通过从不手动编辑文件来防止。 相反,请使用选项下的配置对话框。 一旦用户配置文件出现错误,最好的解决方案可能是将其删除并从设置对话框重新开始。

如果 IDLE 没有任何消息退出,并且它不是从控制台启动的,请尝试从控制台或终端 (python -m idlelib) 启动它,看看这是否会导致错误消息。

在 tcl/tk 早于 8.6.11(参见 About IDLE)的基于 Unix 的系统上,某些字体的某些字符会导致 tk 失败并向终端发送消息。 如果启动 IDLE 以编辑具有此类字符的文件或稍后输入此类字符,则可能会发生这种情况。 如果无法升级 tcl/tk,则重新配置 IDLE 以使用效果更好的字体。


运行用户代码

除了极少数例外,使用 IDLE 执行 Python 代码的结果与通过默认方法直接在文本模式系统控制台或终端窗口中使用 Python 执行相同代码的结果相同。 但是,不同的界面和操作偶尔会影响可见的结果。 例如,sys.modules 以更多条目开头,而 threading.active_count() 返回 2 而不是 1。

默认情况下,IDLE 在单独的操作系统进程中运行用户代码,而不是在运行 shell 和编辑器的用户界面进程中运行。 在执行过程中,它将sys.stdinsys.stdoutsys.stderr替换为从Shell窗口获取输入和向Shell窗口发送输出的对象。 存储在 sys.__stdin__sys.__stdout__sys.__stderr__ 中的原始值没有被触摸,但可能是 None

将打印输出从一个进程发送到另一个进程中的文本小部件比打印到同一进程中的系统终端慢。 这在打印多个参数时最有效,因为每个参数的字符串、每个分隔符、换行符都是单独发送的。 对于开发来说,这通常不是问题,但是如果想在 IDLE 中更快地打印,请格式化并将想要显示的所有内容连接在一起,然后打印单个字符串。 格式字符串和 str.join() 都可以帮助组合字段和行。

IDLE 的标准流替换不会被执行过程中创建的子进程继承,无论是直接由用户代码还是由多处理等模块。 如果此类子进程使用来自 sys.stdin 或 printwriteinput 到 sys.stdout 或 sys.stderr,则应在命令行窗口中启动 IDLE。 然后,辅助子进程将附加到该窗口以进行输入和输出。

如果 sys 由用户代码重置,例如使用 importlib.reload(sys),IDLE 的更改将丢失并且从键盘输入和输出到屏幕将无法正常工作。

当 Shell 获得焦点时,它控制键盘和屏幕。 这通常是透明的,但直接访问键盘和屏幕的功能将不起作用。 其中包括系统特定的功能,用于确定是否按下了某个键,如果按下了,按下了哪个键。

在执行过程中运行的 IDLE 代码将帧添加到调用堆栈中,否则这些帧将不存在。 IDLE 包装 sys.getrecursionlimitsys.setrecursionlimit 以减少额外堆栈帧的影响。

当用户代码直接或通过调用 sys.exit 引发 SystemExit 时,IDLE 将返回到 Shell 提示符而不是退出。


Shell 中的用户输出

当程序输出文本时,结果由相应的输出设备决定。 IDLE执行用户代码时,sys.stdoutsys.stderr连接到IDLE的Shell的显示区域。 它的一些功能是从底层的 Tk 文本小部件继承而来的。 其他是程序化的添加。 在重要的地方,壳牌专为开发而不是生产运行而设计。

例如,Shell 从不丢弃输出。 向 Shell 发送无限输出的程序最终会填满内存,从而导致内存错误。 相比之下,一些系统文本窗口只保留最后 n 行输出。 例如,Windows 控制台保留用户可设置的 1 到 9999 行,默认值为 300。

Tk Text 小部件,以及 IDLE 的 Shell,在 Unicode 的 BMP(基本多语言平面)子集中显示字符(代码点)。 哪些字符使用适当的字形显示,哪些使用替换框取决于操作系统和安装的字体。 制表符导致以下文本在下一个制表位之后开始。 (它们每 8 个“字符”出现一次)。 换行符导致以下文本出现在新行上。 其他控制字符将被忽略或显示为空格、框或其他内容,具体取决于操作系统和字体。 (使用箭头键在这样的输出中移动文本光标可能会出现一些令人惊讶的间距行为。)

>>> s = 'a\tb\a<\x02><\r>\bc\nd'  # Enter 22 chars.
>>> len(s)
14
>>> s  # Display repr(s)
'a\tb\x07<\x02><\r>\x08c\nd'
>>> print(s, end='')  # Display s as is.
# Result varies by OS and font.  Try it.

repr 函数用于表达式值的交互式回显。 它返回输入字符串的更改版本,其中控制代码、一些 BMP 代码点和所有非 BMP 代码点都替换为转义代码。 如上所述,它允许人们识别字符串中的字符,而不管它们如何显示。

正常和错误输出通常与代码输入和彼此分开(在单独的行上)。 它们每个都有不同的高亮颜色。

对于 SyntaxError 回溯,检测到错误的正常 '^' 标记被替换为使用错误突出显示的文本着色。 当从文件运行的代码导致其他异常时,可以右键单击回溯行以跳转到空闲编辑器中的相应行。 如有必要,将打开该文件。

Shell 具有将输出行压缩为“压缩文本”标签的特殊工具。 对于 N 行(默认为 N = 50)的输出,这是自动完成的。 N 可以在 Settings 对话框的 General 页面的 PyShell 部分中更改。 可以通过右键单击输出来压缩行数较少的输出。 这可能是足够长的有用行以减慢滚动速度。

通过双击标签将压缩的输出扩展到位。 也可以通过右键单击标签将其发送到剪贴板或单独的视图窗口。


开发 tkinter 应用程序

IDLE 有意与标准 Python 不同,以促进 tkinter 程序的开发。 在标准 Python 中输入 import tkinter as tk; root = tk.Tk() 没有任何显示。 在 IDLE 中输入相同的内容并出现一个 tk 窗口。 在标准 Python 中,还必须输入 root.update() 才能看到窗口。 IDLE 在后台做同样的事情,大约每秒 20 次,大约每 50 毫秒一次。 接下来输入b = tk.Button(root, text='button'); b.pack()。 同样,在进入 root.update() 之前,标准 Python 中没有任何明显变化。

大多数 tkinter 程序运行 root.mainloop(),通常在 tk 应用程序被销毁之前不会返回。 如果程序使用 python -i 或从 IDLE 编辑器运行,则在 mainloop() 返回之前不会出现 >>> shell 提示,此时没有任何可交互的内容。

从 IDLE 编辑器运行 tkinter 程序时,可以注释掉 mainloop 调用。 然后立即得到一个 shell 提示,并可以与实时应用程序进行交互。 只需要记住在标准 Python 中运行时重新启用 mainloop 调用。


在没有子进程的情况下运行

默认情况下,IDLE 通过使用内部环回接口的套接字在单独的子进程中执行用户代码。 此连接在外部不可见,并且不会向 Internet 发送或从 Internet 接收任何数据。 如果防火墙软件仍然抱怨,您可以忽略它。

如果尝试建立套接字连接失败,Idle 会通知您。 此类故障有时是暂时的,但如果持续存在,则问题可能是防火墙阻止了连接或特定系统的错误配置。 在问题解决之前,可以使用 -n 命令行开关运行 Idle。

如果 IDLE 使用 -n 命令行开关启动,它将在单个进程中运行,并且不会创建运行 RPC Python 执行服务器的子进程。 如果 Python 无法在您的平台上创建子进程或 RPC 套接字接口,这会很有用。 但是,在这种模式下,用户代码与 IDLE 本身并不隔离。 此外,选择运行/运行模块 (F5) 时不会重新启动环境。 如果您的代码已被修改,您必须 reload() 受影响的模块并重新导入任何特定项目(例如 from foo import baz) 如果更改生效。 由于这些原因,最好尽可能使用默认子进程运行 IDLE。

自 3.4 版起已弃用。


帮助和偏好

帮助来源

帮助菜单条目“空闲帮助”显示了库参考中空闲章节的格式化 html 版本。 结果,在只读 tkinter 文本窗口中,与人们在 Web 浏览器中看到的非常接近。 使用鼠标滚轮、滚动条或按住上下箭头键浏览文本。 或者单击 TOC(目录)按钮并在打开的框中选择一个节标题。

帮助菜单条目“Python Docs”打开了广泛的帮助来源,包括教程,可从 docs.python.org/x.y 获得,其中“x.y”是当前运行的 Python 版本。 如果您的系统有文档的离线副本(这可能是一个安装选项),则会打开该副本。

可以随时使用“配置空闲”对话框的“常规”选项卡从帮助菜单中添加或删除选定的 URL。


设置首选项

可以通过“选项”菜单上的“配置空闲”更改字体首选项、突出显示、键和一般首选项。 非默认用户设置保存在用户主目录的 .idlerc 目录中。 通过编辑或删除.idlerc中的一个或多个文件来解决由不良用户配置文件引起的问题。

在“字体”选项卡上,请参阅有关字体和大小对多种语言的多个字符的影响的文本示例。 编辑示例以添加个人感兴趣的其他角色。 使用示例选择等宽字体。 如果特定字符在 Shell 或编辑器中出现问题,请将它们添加到示例的顶部并尝试先更改大小,然后再更改字体。

在突出显示和键选项卡上,选择内置或自定义颜色主题和键集。 要在较旧的 IDLE 中使用较新的内置颜色主题或键集,请将其另存为新的自定义主题或键集,以便较旧的 IDLE 可以访问它。


在 macOS 上空闲

在 System Preferences: Dock 下,可以将“打开文档时首选选项卡”设置为“始终”。 此设置与 IDLE 使用的 tk/tkinter GUI 框架不兼容,并且它破坏了一些 IDLE 功能。


扩展

IDLE 包含一个扩展工具。 可以使用首选项对话框的扩展选项卡更改扩展首选项。 有关详细信息,请参阅 idlelib 目录中 config-extensions.def 的开头部分。 当前唯一的默认扩展名是 zzdummy,一个示例也用于测试。