Default Window Color and Hex Color Codes in Tkinter



A Tkinter window can be customized by adding the properties and attributes such as background color, foreground color, width, height, etc.

The color attribute in config() defines the default color of the main window. We can set the color of the window by defining either Hex Color (e.g., #000 for Black) or the Name of the color.

Example

# Import the required libraries
    from tkinter import *

    #Create an instance of Tkinter Frame
    win = Tk()

    #Set the geometry
    win.geometry("700x350")

    #Set the default color of the window
    win.config(bg = '#24f3f0')
    # win.config(bg = 'SkyBlue1')

    Label(win, text= "Hey There! Welcome to TutorialsPoint", font= ('Helvetica 22 bold'), foreground="navy").pack()

    win.mainloop()

Output

Running the above code will display a window with the background color that we have set in the code.

The window color can be customized either by defining the HEX or RGB value or the Color name.

Updated on: 2021-05-25T08:50:36+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements