IDLE 用户界面——IDLE启动细节
大多数读者应该能立即使用 IDLE,因为它是当今 Mac OS X 和大多数 Linux 安装过程的一个标准组件,且它在 Windows 上被自动地和标准 Python 安装到一起。然而,因为平台各异,需要在打开这个 GUI 前给出一些指引。
技术上讲,IDLE 是一个使用标准库的 tkinter(在 Python 2.X 中名为 Tkinter) GUI 工具包来构建其窗口的 Python 程序。这让 IDLE 可移植 —— 在所有主流桌面平台上工作一致 —— 但也意外着需要在 Python 中得到 tkinter 的支持来使用 IDLE。这个支持在 Windows,Macs 和 Linux 上是标准的,但在一些系统上,它附带一些注意事项,且在各平台上启动可以有差异。下面是一些平台特别的提示:
-
On Windows 7 and earlier, IDLE is easy to start—it’s always present after a Python install, and has an entry in the Start button menu for Python in Windows 7 and earlier (see Figure 2-1, shown previously). You can also select it by right-clicking on a Python program icon, and launch it by clicking on the icon for the files idle.pyw or idle.py located in the idlelib subdirectory of Python’s Lib directory. In this mode, IDLE is a clickable Python script that lives in C:\Python33\Lib\idlelib, C:\Python27\Lib\idlelib, or similar, which you can drag out to a shortcut for one-click access if desired.
-
On Windows 8, look for IDLE in your Start tiles, by a search for “idle,” by browsing your “All apps” Start screen display, or by using File Explorer to find the idle.py file mentioned earlier. You may want a shortcut here, as you have no Start button menu in desktop mode (at least today; see Appendix A for more pointers).
-
在 Mac OS X 上 IDLE 需要的所有东西都作为操作系统的标准组件存在。IDLE 应该在 MacPython(或 Python N.M) 程序文件夹下面的 Applications 中可以启动。这里注意:由于稳定版本依赖,一些 OS X 版本可能需要安装更新的 tkinter 支持(这里就不对读者介绍这么复杂的东西了);参见 python.org 的下载页获取详情。
-
在 Linux 上,当前 IDLE 通常也是作为一个标准组件存在。它可能采用在你路径中的一个 idle 可执行文件或脚本的形式;在 shell 中输入它来检查。在一些机器上,它可能需要安装(参见附录 A 获取指示),且在其他系统上可能需要从命令行或图标点击来启动 IDLE 的顶层脚本:运行在 Python 的 /usr/lib 目录中的 idlelib 子目录中的 idle.py(运行
find
来找到确切的位置)
因为 IDLE 只是在标准库中的模块搜索路径上的一个 Python 脚本,还可以在任何平台,任何目录在系统命令 shell 窗口通过输入下面的语句来运行它(比如在 Windows 上的命令提示符),然而这将需要参见附录 A 和 Part V 来获取关于 Python 的 -m
标记 和 这里需要的 “.” 包语法的更多知识(在本书的这个节点上盲目的信任就足够了):
c:\code> python -m idlelib.idle # Run idle.py in a package on module path
要获取更多关于在 Windows 和其他平台的安装问题和使用的注意事项,确保参考附录 A 和 Python 标准手册中的 “Python 设置和用法” 中关于你的平台的注意事项。