Tkinter Color Changer Application

  • Share this:

Code introduction


This code creates a Tkinter window with a button. When the button is clicked, it opens a color selector dialog that allows the user to choose a color, which is then applied to the background of a label.


Technology Stack : Tkinter, colorchooser

Code Type : Tkinter GUI

Code Difficulty : Intermediate


                
                    
def random_color_button():
    import tkinter as tk
    from tkinter import colorchooser

    def choose_color():
        color_code = colorchooser.askcolor(title="Choose color")
        label.config(bg=color_code[1])

    root = tk.Tk()
    button = tk.Button(root, text="Choose Color", command=choose_color)
    button.pack(pady=20)
    label = tk.Label(root, text="Click the button to choose a color")
    label.pack(pady=20)
    root.mainloop()