Python Execution Black-and-White Invert

Asked 2 years ago, Updated 2 years ago, 24 views

Stored the python code.When you run the py file, it runs in the cmd window.

I'd like to see black letters on a white background, such as running this in a notepad.

Is there a separate execution program?

Or is there a code that reverses the background to white and the letters to black?

python

2022-09-21 12:38

2 Answers

Specifying the background of the console window and the color of the text is set by the app, not related to Python.

If you are in a Windows environment and you have installed Python as an installer, try running it with the IDLE editor that is created during installation.


2022-09-21 12:38

I think the answer is a little late, but...

The Python module allows you to specify a white background and font.

The result may be quite different from your imagination, but I'm uploading the code just in case.

Code that changes the background to white, the letters to black, and sets the font to D2coding.

import os
import ctypes

class COORD(ctypes.Structure):
    _fields_ = [("X", ctypes.c_short), ("Y", ctypes.c_short)]

class CONSOLE_FONT_INFOEX(ctypes.Structure):
    _fields_ = [("cbSize", ctypes.c_ulong),
                ("nFont", ctypes.c_ulong),
                ("dwFontSize", COORD),
                ("FontFamily", ctypes.c_uint),
                ("FontWeight", ctypes.c_uint),
                ("FaceName", ctypes.c_wchar * 32)]

font = CONSOLE_FONT_INFOEX()
font.cbSize = ctypes.sizeof(CONSOLE_FONT_INFOEX)
font.nFont = 12
font.dwFontSize.X = 11
font.dwFontSize.Y = 18
font.FontFamily = 54
font.FaceName = "D2coding" # 'D2coding' font settings

handle = ctypes.windll.kernel32.GetStdHandle(-11)
ctypes.windll.kernel32.SetCurrentConsoleFontEx(
        handle, ctypes.c_long(False), ctypes.pointer(font))

os.system('colorf0') #white background, changing to black characters

# a test statement
print()
print("Let's Love Hangul!"')
input(':')

Note: https://stackoverflow.com/questions/3592673/change-console-font-in-windows/26329412


2022-09-21 12:38

If you have any answers or tips


© 2025 OneMinuteCode. All rights reserved.