thkinter label with white police and black background in python

To create a Label with white text on black background in Tkinter, you can use the following code:

main.py
import tkinter as tk

root = tk.Tk()

label = tk.Label(root, text="Hello, World!", bg="black", fg="white")
label.pack()

root.mainloop()
137 chars
9 lines

In this code, we first import the tkinter module and create an instance of the Tk class.

We then create a Label widget using the Label constructor, passing in the root as the first argument and the text we want to display as the second argument.

To style the label, we set the bg (background) option to "black" and the fg (foreground) option to "white".

Finally, we use the pack method to add the Label widget to the root window and start the main event loop using the mainloop method.

gistlibby LogSnag