By default a Tkinter label text will have the background the default of the element to which it belongs. If you want to change the default background of the text you need to make use of the background attribute.
Syntax: background='color-name|hex-color-code'
Example:from tkinter import *
window = Tk()
my_text_label = Label(window, text='I want to change the background \n of this label to yellow!', background='yellow')
my_text_label.pack()
window.mainloop()
Note: You can also use hexadecimal color codes example,
⛏️ You can also use a short-form of this attribute: example: bg='#2848273'
Example:from tkinter import *
window = Tk()
my_label = Label(window, text='I want to change the background \n of this label to grey!', bg='#999999')
my_label.pack()
window.mainloop()
More Posts related to Python,
- Python List of Lists with Examples
- Fix: ERROR: Could not find a version that satisfies the requirement tkinter (from versions: none) ERROR: No matching distribution found for tkinter
- How to Convert Python Notebook .ipynb (JSON) to Executable .py Module
- ModuleNotFoundError: No module named qdarkstyle.colorsystem [Python]
- Python: Pandas Merge Indicator (Left, Right and Both) Example
- Fix: EOFError Exception in Python
- How to URL Decode a Query String in Python
- How to take user input from the console in a Python program
- Compare two lists in Python and return matches
- How to change the Python Default version
- Fix: KeyError: exception in Python
- How to get the Execution Time of A Python Program
- Fix: ModuleNotFoundError: No module named boto3 [Python]
- How to get unique values from a list in Python
- How to pip install Python Modules in VSCode
- Python: Fix - TypeError: NoneType object is not iterable
- How to delete a file using Python code example
- How to create a dictionary comprehension in Python
- Python: Get just the filename without extension using Path
- How to comment out a block of code in Python
- How to add two float numbers in Python
- Python: How to POST Json Data with HTTP Request
- Get MD5 Hash as Checksum of a String in Python
- Python - Convert float to String
- How to Parse XML String in Python
More Posts:
- How to Install npm using Mac Terminal - MacOS
- Fix SharePoint 2019 installation error This product requires Visual C++ Redistributable Package for Visual Studio 2017 - SharePoint
- Know installed PowerShell Version on Mac - Powershell
- Python 3.x : How to Convert String to Bytes - Python
- Create Safari Shortcut on Mac Desktop - MacOS
- PHP Base64 encoding decoding a variable - PHP
- How to verify if java is installed on the computer and get version detail - Java
- How to Remove Widgets from macOS Sonoma 14 Desktop - MacOS