python IDLE 改变窗口背景颜色

初学python时,许多人会选择使用python自带的idle作为练习的ide。然而,默认的代码配色和语法高亮主题可能并不适合所有人。

那么,能否将IDLE配置成像sublime Text那样的主题呢?

答案是肯定的。

效果图如下:

python IDLE 改变窗口背景颜色

立即学习Python免费学习笔记(深入)”;

如何实现呢?别着急,按照以下步骤逐一进行即可。首先,需要找到名为config-highlight.cfg的文件。该文件的路径如下:

linux系列系统下,路径为(~表示用户目录):~/.idlerc/

windows XP下,路径为:C:Documents and Settings.idlerc

在Windows 7下,路径为:C:Users.idlerc在Windows系统中,可以直接在开始菜单的运行框或地址栏中输入以下路径:

%USERPROFILE%.idlerc找到config-highlight.cfg文件后,需要对其进行编辑。如果找不到该文件,可以新建一个config-highlight.cfg。

对于命令行爱好者,可以在Linux系统下使用以下命令:

# for Linux vi ~/.idlerc/config-highlight.cfg

在Windows系统下,可以使用以下命令:

notepad %USERPROFILE%.idlercconfig-highlight.cfg

现在,我们应该已经打开了config-highlight.cfg文件并准备好进行编辑。例如,可以通过修改文件内容来实现两个名为Obsidian和tango的代码高亮主题:

[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

tango这个主题就是文章开头展示的主题效果,酷吧?不过,修改了config-highlight.cfg文件后,事情还没有结束。还需要在Python IDLE中选择我们的主题。如果已经打开Python IDLE,请保存必要文件并重新启动IDLE。启动后,依次选择菜单上的Options – Configure IDLE…

选择Highlighting选项卡,然后在select a Custom Theme中选择刚才配置的两个主题之一,这里我选择了tango。

完成配置后,点击Apply或者OK,查看效果。有人可能会问字体如何配置?这很简单,在Highlighting选项卡旁边有一个Fonts/Tabs选项卡,可以用来配置字体和缩进宽度:

完成这些步骤后,一个全新的界面就应该呈现了。如果看不到效果,请重启Python IDLE。

以上就是

© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享