- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use rgb color codes in tkinter?
Tkinter has many inbuilt features and attributes that help the application developer to build a robust and featured application. We can set the attributes such as background color, foreground color, and other properties of a widget using the configure method in Tkinter.
To set the background color or foreground color of a widget, we can use both default and RGB color codes. RGB is defined by the 6 digit alphanumeric character containing different digits of R, G, B values. In order to use RGB color codes in tkinter, we have to define it using the format #aab123.
Example
# Import the required libraries from tkinter import * from tkinter import ttk # Create an instance of tkinter frame win = Tk() # Set the size of the tkinter window win.geometry("700x350") # Configure the color of the window win.configure(bg='#65A8E1') # Define the style for combobox widget style = ttk.Style() style.theme_use('xpnative') # Define an event to close the window def close_win(e): win.destroy() # Add a label widget label = ttk.Label(win, text="Eat, Sleep, Code and Repeat", font=('Times New Roman italic', 22), background="black", foreground="white") label.place(relx=.5, rely=.5, anchor=CENTER) win.mainloop()
Output
Executing the above code will display a window with some customized background color.
Now, find a new color code to change the background color of the window.
- Related Articles
- Default window color Tkinter and hex color codes in Tkinter
- RGB color to hexadecimal color JavaScript
- Hexadecimal color to RGB color JavaScript
- How can RGB color space be converted to a different color space in Python?
- Color Shades using RGB Led
- C Program to Change RGB color model to HSV color model
- How to pass RGB color values to Python's Matplotlib eventplot?
- How to change text cursor color in Tkinter?
- JavaScript to generate random hex codes of color
- How to create a trackbar as the RGB color palette using OpenCV Python?
- How to change the mouse pointer color in Tkinter?
- How to change the color of ttk button in Tkinter?
- How to use Thread in Tkinter Python?
- How to change the background color of a Treeview in Tkinter?
- How to set the background color of a ttk.Combobox in tkinter?

Advertisements