1、修改默认主题:代码配色及语法高亮
(1)首先找到python的主题配置文件config-highlight.cfg,没有就创建一个:
Linux系统下的路径为:<用户目录>/.idlerc/
winxp下路径为:C:\Documents and Settings\<用户名>\.idlerc\
win7下路径为:C:\Users\<用户名>\.idlerc\
(2)再编辑一下,这里提供几个主题:
[Obsidian] definition-foreground = #678CB1 error-foreground = #FF0000 string-background = #293134 keyword-foreground = #93C763 normal-foreground = #E0E2E4 comment-background = #293134 hit-foreground = #E0E2E4 builtin-background = #293134 stdout-foreground = #678CB1 cursor-foreground = #E0E2E4 break-background = #293134 comment-foreground = #66747B hilite-background = #2F393C hilite-foreground = #E0E2E4 definition-background = #293134 stderr-background = #293134 hit-background = #000000 console-foreground = #E0E2E4 normal-background = #293134 builtin-foreground = #E0E2E4 stdout-background = #293134 console-background = #293134 stderr-foreground = #FB0000 keyword-background = #293134 string-foreground = #EC7600 break-foreground = #E0E2E4 error-background = #293134 [tango] definition-foreground = #fce94f error-foreground = #fa8072 string-background = #2e3436 keyword-foreground = #8cc4ff normal-foreground = #ffffff comment-background = #2e3436 hit-foreground = #ffffff break-foreground = #000000 builtin-background = #2e3436 stdout-foreground = #eeeeec cursor-foreground = #fce94f hit-background = #2e3436 comment-foreground = #73d216 hilite-background = #edd400 definition-background = #2e3436 stderr-background = #2e3436 break-background = #2e3436 console-foreground = #87ceeb normal-background = #2e3436 builtin-foreground = #ad7fa8 stdout-background = #2e3436 console-background = #2e3436 stderr-foreground = #ff3e40 keyword-background = #2e3436 string-foreground = #e9b96e hilite-foreground = #2e3436 error-background = #2e3436 [blackboard] keyword-background = #0C1021 definition-foreground = #D63A1B error-foreground = #ff0000 string-background = #0C1021 keyword-foreground = #FBDE2D hilite-foreground = #000000 comment-background = #0C1021 hit-foreground = #ffffff builtin-background = #0C1021 stdout-foreground = #eeeeee cursor-foreground = #ffcc00 break-background = #ffff55 comment-foreground = #505050 hilite-background = gray definition-background = #0C1021 stderr-background = #0C1021 hit-background = #0C1021 console-foreground = #87ceeb normal-background = #0C1021 builtin-foreground = #fd9902 stdout-background = #0C1021 console-background = #0C1021 stderr-foreground = #ff3e40 normal-foreground = #F8F8F8 string-foreground = #61CE3C break-foreground = black error-background = #000000 [twilight] keyword-background = #141414 definition-foreground = #c86428 error-foreground = #ff0000 string-background = #141414 keyword-foreground = #c2964b hilite-foreground = #00ffff comment-background = #141414 hit-foreground = #ffffff builtin-background = #141414 stdout-foreground = #eeeeee cursor-foreground = #ffcc00 break-background = #ffff55 comment-foreground = #524d53 hilite-background = #0000a0 definition-background = #141414 stderr-background = #141414 hit-background = #141414 console-foreground = #87ceeb normal-background = #141414 builtin-foreground = #ce3e24 stdout-background = #141414 console-background = #141414 stderr-foreground = #ff3e40 normal-foreground = #FFFFFF string-foreground = #61CE3C break-foreground = black error-background = #000000 [desert] keyword-background = #333333 definition-foreground = #98fb98 error-foreground = #ff0000 string-background = #333333 keyword-foreground = #cc6600 hilite-foreground = #000000 comment-background = #333333 hit-foreground = #ffffff builtin-background = #333333 stdout-foreground = #eeeeee cursor-foreground = #ffcc00 break-background = #ffff55 comment-foreground = #87ceeb hilite-background = gray definition-background = #333333 stderr-background = #333333 hit-background = #333333 console-foreground = #87ceeb normal-background = #333333 builtin-foreground = #519e51 stdout-background = #333333 console-background = #333333 stderr-foreground = #ff3e40 normal-foreground = #f0e68c string-foreground = #ffa0a0 break-foreground = black error-background = #000000 [cobalt] keyword-background = #001B33 definition-foreground = #FFDD11 error-foreground = #ff0000 string-background = #001B33 keyword-foreground = #FF7222 hilite-foreground = #00ffff comment-background = #001B33 hit-foreground = #ffffff builtin-background = #001B33 stdout-foreground = #eeeeee cursor-foreground = #ffcc00 break-background = #ffff55 comment-foreground = #007699 hilite-background = #0000a0 definition-background = #001B33 stderr-background = #001B33 hit-background = #001B33 console-foreground = #87ceeb normal-background = #001B33 builtin-foreground = #D40E36 stdout-background = #001B33 console-background = #001B33 stderr-foreground = #ff3e40 normal-foreground = #F8F8F8 string-foreground = #61CE3C break-foreground = black error-background = #000000
2、快捷键
我觉得主要就是一个代码补全,一个自动完成。
(1)自动完成(expand-word)是指用编辑器内已经写过的代码来补全当前代码。在菜单“Edit”中选择“Expand Word”,也可以在菜单“Options”的“Keys”中修改快捷键(默认快捷键是Alt+/)。
(2)代码补全(force-open-completions)是指当前变量的某个函数或者属性值的补全。在菜单“Edit”中选择“Show Completions”,也可以在菜单“Options”的选项“Keys”中修改快捷键(默认快捷键是Ctrl+Space),但是这个默认快捷键与输入法冲突所以用不了。
一种解决办法是修改快捷键:在菜单“Options”的选项“Keys”中找到“force-open-completions”,修改之(我发现不能修改为Tab按键)。
另外一种简单的解决办法就是在代码文件前面加上如下代码,加了之后Tab按键就能用于代码补全了,加上原先的Alt+/能够用于自动完成,所以写起代码来特别方便。
import rlcompleter, readline readline.parse_and_bind('tab: complete')
注意代码补全时space为选定,而不是Enter!
(3)其他常用按键:
ALT+P:对历史命令进行上翻页(history-previous)
ALT+N:对历史命令进行下翻页(history-next)
Ctrl+C:中断执行(interrupt-execution)
Tab:智能缩进(smart-indent)
Ctrl+]:整体增加缩进(indent-region)
Ctrl+[:整体减少缩进(dedent-region)
Alt+3:整体加注释(comment-region)
Alt+4:整体去注释(uncomment-region)
3、调试
(1)在“Python Shell”窗口中单击“Debug”菜单中的“Debugger”菜单项,就可以启动IDLE的交互式调试器。这时IDLE会打开“Debug Control”窗口,并在“Python Shell”窗口中输出“[DEBUG ON]”并后跟一个“>>>”提示符。
(2)按F5执行python代码,此时我们可以在“Debug Control”窗口查看局部变量和全局变量等有关内容;同时也
可以在“Python Shell”窗口中输入命令(等于在调试器中执行)。
(3)“Debug Control”窗口上面的调试按键和VS差不多:Go-继续执行完,Step-步入,Over-步过,Out-跳出,Quit-退出调试。
(4)如果要退出调试器,可以再次单击“Debug”菜单中的“Debugger”菜单项,IDLE会关闭“Debug Control”窗口,并在“Python Shell”窗口中输出“[DEBUG OFF]”。