Python Dark Mode

Abid Ullah Oct 10, 2023
  1. Dark Mode in Python
  2. The Python IDLE
Python Dark Mode

The purpose of this Python article is to explain how you can apply dark mode in Python. The method of making dark mode in Python will be described here, and its usage with a good example.

Dark Mode in Python

Object-oriented, high-level, interactive, interpreted, and general-purpose Python is a programming language. Since 1991, it has been in development.

With Python, programmers can write programs and instructions using fewer lines of code, attracting millions of developers.

Transform your Python IDLE 2.7 into a Dark Theme, reducing eye strain in low-light conditions if you are a Python developer, especially if you are a night-owl programmer. For those who wish to experience the Monokai theme of Sublime Text, Python IDLE 2.7 can be customized to add the Dark theme.

This article will teach you how to use custom color schemes with Python’s built-in IDE, IDLE. Adjusting how IDLE highlights your code can make your editor more intuitive and boost your performance.

Writing code is much more challenging for us when the color theme in our editor is uncomfortable or straining. Too much contrast between the background and the foreground makes it difficult to read your code.

Using a theme that does not work for you can be confusing or unintuitive, as you may expect certain pieces of code to be highlighted in a certain color, but your IDE is using a completely different one. Your code comments may be displayed in a bright red color when you prefer them to be more subdued.

The Python IDLE

Python IDLE, or Integrated Development and Learning Environment (IDLE), is a standard IDE included with the Python installation package for the Python programming language.

By searching for IDLE in the Start menu in Windows Operating System, you can open Python IDLE.

Python IDLE settings

Python IDLE is not included by default in Python distributions for Linux and macOS.

The Python IDLE can be installed on Ubuntu Linux by using the following command:

$ sudo apt-get install idle

A single-line Python statement can be executed using Python IDLE. Python IDLE is used by developers primarily for developing, modifying, executing, and debugging Python scripts.

A Python IDLE text editor contains all the features you need to write Python scripts efficiently and effectively.

Aside from syntax highlighting, autocompletion, and smart indent, it also includes some awesome features. IDLE’s debugger is a key feature that provides stepping and breakpoints.

The official website of Python has a download link that automatically comes with Python IDLE.

Reasons to Add a Dark Theme to Your Python IDLE

Nowadays, dark themes are becoming increasingly popular among night-owl programmers. Some people like the vibe of dark themes, while others use them to reduce eye strain and save battery life.

In the eye doctor’s profession, programmers are the main source of income.

Pros:

Low-light conditions can reduce eye strain with dark themes, especially at night. The contrast between foreground and background reduces eye strain.

Python IDLE syntax highlighting can be easier to read with dark themes like Monokai. Enjoy coding while protecting your most precious organ - your eye.

Python IDLE Dark Theme Code (Monokai Theme Included)

Python IDLE already includes the following code, which you’ll need in the next section, which explains how to make your Python IDLE have a dark theme.

As part of the Monokai Theme code, syntax highlighting and various text editor components’ colors are changed by default.

Example code:

[monokai]
normal-foreground= #F8F8F2
normal-background= #272822
keyword-foreground= #F92672
keyword-background= #272822
builtin-foreground= #66D9EF
builtin-background= #272822
comment-foreground= #75715E
comment-background= #272822
string-foreground= #E6DB74
string-background= #272822
definition-foreground= #A6E22E
definition-background= #272822
hilite-foreground= #F8F8F2
hilite-background= gray
break-foreground= black
break-background= #ffff55
hit-foreground= #F8F8F2
hit-background= #171812
error-foreground= #ff3338
error-background= #272822
cursor-foreground= #F8F8F2
stdout-foreground= #DDDDDD
stdout-background= #272822
stderr-foreground= #ff3338
stderr-background= #272822
console-foreground= #75715E
console-background= #272822

Activating Theme

  1. Place config-highlight.cfg in your IDLE config directory, which is commonly located at C:/Users/.idlerc, C:/Users/%user%/.idlerc, Python/Lib/idlelib, /home/.idlerc, $HOME/.idlerc.

  2. Select Highlighting under Options > Configure > IDLE.

  3. The Dracula theme can be selected under Custom Themes. Writing multiple lines containing functions/classes in the IDLE shell is not advisable.

    If this is the case, you can select New File from IDLE’s File menu.

  4. There are several options in IDLE’s Format, Edit, and Options menus.

    The Python IDLE Shell

  5. This allows you to select any font face and size, make the font bold, and even set the indentation width.

  6. The menu icon is located in the top-right corner of the IDE window and allows users to swiftly choose between bright and dark color themes in the Python IDE. Wing switches to the light or dark themes on the first User Interface options page when Dark Theme or Light Theme is selected.

  7. Wing also can mimic the OS display style on Windows and macOS. At the moment, Windows always has a light theme.

  8. The wing will follow the system-defined display style on macOS. It should be noted that you can choose the editor’s theme independently of the main display theme in both scenarios.

  9. The IDLE program provides you with this feature so that each user can work with the font size that is most comfortable for them.

    You may need an IDE to increase the font size when your monitor is too small. You can relieve your eyes with IDLE and give them a sense of relief.

  10. You can also change the indentation, which follows PEP-8 coding guidelines, which is set to 4 spaces by default.

    Configuring Python IDLE

  11. Keys: This feature allows you to map different key presses to actions, also known as keyboard shortcuts. You need these components to increase your overall productivity when using an IDE.

    Whether you want to come up with your keyboard shortcuts or use the defaults, it’s up to you.

  12. The keys are displayed in an Action-Key format, which shows the action performed when a specific key or key is pressed. Developers rarely use the IDLE keys feature, but it makes life easier for those who need to write a lot of code quickly.

  13. Using the horizontal tab at the top, select Highlights.

    Using the Highlights

  14. You can choose IDLE Classic/IDLE Dark/IDLE New on the right-hand side under Highlight Theme.

  15. Then click OK after clicking Apply.

  16. Now, you may restart your system and open Python IDLE. From the menu bar, select Options > Configure IDLE > Highlighting, and you will be able to see the Monokai theme under the Highlighting themes section. Select Monokai dark theme.

    The Darkmode

This article’s final section covered installing a dark theme in Python IDLE so you can run scripts like a pro without straining your eyes.

The following subjects are covered:

  1. What is Python IDLE?
  2. How can we set up Python IDLE on our system?
  3. Why is it necessary to give your Python IDLE a black theme?
  4. And the way to make your Python IDLE have a dark theme.

In this Python article, we hope to have demonstrated how to add a dark theme in Python with step-by-step guidelines.

Author: Abid Ullah
Abid Ullah avatar Abid Ullah avatar

My name is Abid Ullah, and I am a software engineer. I love writing articles on programming, and my favorite topics are Python, PHP, JavaScript, and Linux. I tend to provide solutions to people in programming problems through my articles. I believe that I can bring a lot to you with my skills, experience, and qualification in technical writing.

LinkedIn