修改Python IDLE代碼配色及語法高亮主題

HOW TO DO?別急,下面按我介紹的一步一步來就可以了,首先要找到名為config-highlight.cfg的文件,這個(gè)文件位于哪里呢?我列了一份可以找到它的路徑清單:
在Linux系列系統(tǒng)下路徑為(~表示用戶目錄):
~/.idlerc/
在Windows XP下路徑為:
C:\Documents and Settings\<用戶名>\.idlerc\
在Windows 7下路徑為:
C:\Users\<用戶名>\.idlerc\
對(duì)于Windows可以直接打開開始運(yùn)行或者在地址欄輸入下面的路徑確認(rèn)即可:
%USERPROFILE%\.idlerc\
找到這個(gè)名叫config-highlight.cfg文件后接下來就需要編輯它了,怎么?找不到?沒關(guān)系,我們可以新創(chuàng)建一個(gè)config-highlight.cfg。
當(dāng)然,說到編輯,命令控們也可以嘗試下面的命令,在Linux系統(tǒng)下:
# for Linuxvi~/.idlerc/config-highlight.cfg
在Windows系統(tǒng)下:
notepad%USERPROFILE%\.idlerc\config-highlight.cfg
好了,現(xiàn)在我們應(yīng)該已經(jīng)打開config-highlight.cfg這個(gè)文件并做好編輯的準(zhǔn)備了,比如說我可以通過修改這個(gè)文件為下面內(nèi)容來實(shí)現(xiàn)兩個(gè)名為Obsidian和tango的代碼高亮主題:
[Obsidian]definition-foreground= #678CB1error-foreground= #FF0000string-background= #293134keyword-foreground= #93C763normal-foreground= #E0E2E4comment-background= #293134hit-foreground= #E0E2E4builtin-background= #293134stdout-foreground= #678CB1cursor-foreground= #E0E2E4break-background= #293134comment-foreground= #66747Bhilite-background= #2F393Chilite-foreground= #E0E2E4definition-background= #293134stderr-background= #293134hit-background= #000000console-foreground= #E0E2E4normal-background= #293134builtin-foreground= #E0E2E4stdout-background= #293134console-background= #293134stderr-foreground= #FB0000keyword-background= #293134string-foreground= #EC7600break-foreground= #E0E2E4error-background= #293134[tango]definition-foreground= #fce94ferror-foreground= #fa8072string-background= #2e3436keyword-foreground= #8cc4ffnormal-foreground= #ffffffcomment-background= #2e3436hit-foreground= #ffffffbreak-foreground= #000000builtin-background= #2e3436stdout-foreground= #eeeeeccursor-foreground= #fce94fhit-background= #2e3436comment-foreground= #73d216hilite-background= #edd400definition-background= #2e3436stderr-background= #2e3436break-background= #2e3436console-foreground= #87ceebnormal-background= #2e3436builtin-foreground= #ad7fa8stdout-background= #2e3436console-background= #2e3436stderr-foreground= #ff3e40keyword-background= #2e3436string-foreground= #e9b96ehilite-foreground= #2e3436error-background= #2e3436
tango這個(gè)主題就是文章一開始展示的主題效果,怎么樣是否很酷?等等,我們修改了config-highlight.cfg這個(gè)文件并不意味著事情結(jié)束了,我們還需要在Python IDLE中選擇我們的主題,這時(shí)如果已經(jīng)打開Python IDLE,請(qǐng)保存必要文件并重新開啟IDLE,開啟后依次選擇菜單上Options – Configure IDLE…

選擇Highlighting選項(xiàng)卡,然后Select選擇a Custom Theme,如下圖所示,選擇剛才配置的兩個(gè)主題之一,我這里選擇tango。

完成配置后點(diǎn)擊Apply或者OK,看看效果吧,有童鞋要問字體怎么配置?這個(gè)容易,在Highlighting選項(xiàng)卡旁邊有個(gè)Fonts/Tabs選項(xiàng)卡,可以用來配置字體和縮進(jìn)寬度的:

好了,做完這些一個(gè)嶄新的界面就應(yīng)該呈現(xiàn)了,如果看不到效果請(qǐng)重啟Python IDLE。