- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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.
# 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()
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.
- Default window color Tkinter and hex color codes in Tkinter
- C Program to Change RGB color model to HSV color model
- How can RGB color space be converted to a different color space in Python?
- How to pass RGB color values to Python's Matplotlib eventplot?
- How to change text cursor color in Tkinter?
- How to change the mouse pointer color in Tkinter?
- How to use Thread in Tkinter Python?
- How to change the color of ttk button in Tkinter?
- Color game using Tkinter in Python
- How to Use Images as Backgrounds in Tkinter?
- How to use a custom font in Tkinter?
- How to use the Entry widget in Tkinter?