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()
- tkinter - Hello World! Program
- How to install Python Specific version (3.8, 3.9 or 3.10) using Brew
- How to install SpaCy (NLP Library) on Mac
- Python matplotlib segmentation fault: 11 macOS Big Sur
- How to uninstall pip Python packages
- 3 Ways to find if element is present in a List in Python
- How to Convert Python String to DateTime Object
- Python f-strings Formatted String Literals Syntax and Examples
- Where does brew install python in macOS
- Take input argument from command line in Python Programming
- Advanced print() Function Tutorial and Techniques for Python Developers
- How to add borders to tkinter label text
- Whats new in Python 3.10 Pre-release
- Float built-in function in Python
- List of All 35 Reserved Keywords in Python Programming Language 3.11
- How to check if Key Exists in Python Dictionary?
- Read a file line by line in Python Program
- ModuleNotFoundError: No module named qdarkstyle.colorsystem [Python]
- What is the Max and Minimum Value of int type in Python?
- What is Terminal Velocity and its Formula? How to calculate it programmatically?
- Fix: TypeError: can only concatenate str (not int) to str in Python
- How to take user input from the console in a Python program
- [Fix] TypeError: str object is not callable in Python
- 3 Python program to add two numbers
- How to delete a file using Python code example
- How to find lost AirPods? - HowTos
- What is Microsoft 365 Message You are using more licenses on your trial than what you will purchase once the free trial ends. - Microsoft
- How to Install Git on Ubuntu Linux - Git
- How to empty Trash in macOS? - MacOS
- How to zoom-in or zoom-out in Windows Notepad - NotepadPlusPlus
- Android [SDK Manager] The system cannot find the path specified - Android-Studio
- SharePoint error 2130575251 - The security validation for this page is invalid and might be corrupted - SharePoint
- How to Apply Themes to Notepad++ - NotepadPlusPlus