Custom IDLE Themes Tutorial
In this post I will teach you how to use custom color schemes with IDLE, Python’s built-in IDE. Using custom IDLE themes is a great way to make your editor more intuitive and boost your productivity by adjusting how IDLE highlights your code. Personally I find it much harder to write my code if my editor has an uncomfortable or straining color theme. Too much contrast between the background and foreground can be very straining on your eyes and make it difficult to read your own code. A theme that doesn’t work well for you can be confusing or simply unintuitive, as you may be expecting a certain piece of code to be highlighted in one color, but your IDE is using a totally different style. Perhaps your code comments are being shown in a bright red when you would like them to be more subdued.
To select between the default themes, go to Options > Configure IDLE and navigate to the Highlights tab. On the right side of the panel, there will be two radio buttons to choose between default themes or custom ones. Choose your theme from the dropdown list and click the Apply button at the bottom of the window. The theme is now activated and you will see the changes in your IDLE window.
You can also make changes to your themes in the Highlights tab. Under “Custom Highlighting” you will see a dropdown list where you can select a particular item to edit. For each item, you can edit both the foreground and background color by clicking the “Choose Color for:” button with either “Foreground” or “Background” selected. You can see a preview of your changes on the left side of the window. When you’re finished editing the highlight colors, click on the button labeled “Save as New Custom Theme” underneath the preview pane, and enter a name for your theme, then click Save.
Now, on to the themes files. If you prefer to edit your themes via the Settings menu, then you don’t need to mess with these files. But if you find a theme on the internet that you want to use, then this is how you will install them.
The default built-in themes are located in a file called config-highlight.def
, which on Windows will be located in your Python installation directory with a location such as C:\Python39\Lib\idlelib\config-highlight.def
. You should not edit this file, as it only serves to define the default themes – but if you want to base your custom theme on one of these, then you can copy them from here and paste your new version into the custom themes file discussed in the next paragraph.
On Windows, the file you want to edit to add new highlight themes is C:\Users\<USERNAME>\.idlerc\config-highlight.cfg
. On most Linux distros this file will be located in your home directory at <home_directory>/.idlerc/config-highlight.cfg
. You may have to create it if it doesn’t already exist; but if you have saved any custom themes from the Settings menu in IDLE, then the file will be here. Note the different extension – the filenames are similar, but the custom themes file has a .cfg
extension while the built-in themes file has a .def
extension.
To sum it up, the 2 files in question are:
- Built-in themes –
config-highlight.def
- Custom themes –
config-highlight.cfg
A custom highlight theme will look something like this, which you will copy & paste into config-highlight.cfg
:
[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
Copy this theme definition into your config-highlight.cfg
file, with a blank line separating each theme. The colors for each item are in hex format, and the name of the theme will be in brackets at the beginning of each theme definition. The next time you open IDLE, it will read your custom highlight themes automatically and you will be able to select them in the Preferences window.
I have uploaded for you a sample themes file containing several custom themes. Place the config file at C:\Users\<USERNAME>\.idlerc\config-highlight.cfg
(if using Linux, then ~/.idlerc/config-highlight.cfg
). I did not create the themes in it, so please appreciate the efforts of the original authors. You are free to use it as you wish.