import random
import tkinter as tk


def generate_random_color():
    color_int = random.randint(0, 0xFFFFFF)
    return f"#{color_int:06x}"


def generate_color_palette(n=5):
    return [generate_random_color() for _ in range(n)]


def show_palette():
    # Clear the frame
    for widget in frame.winfo_children():
        widget.destroy()

    palette = generate_color_palette(5)
    for color in palette:
        swatch = tk.Frame(frame, bg=color, width=100, height=50)
        swatch.pack(side=tk.LEFT, padx=5)

    # Update the label to show the hex codes
    color_label.config(text=" ".join(palette))


app = tk.Tk()
app.title("Random Color Palette Generator")

frame = tk.Frame(app)
frame.pack(pady=20)

color_label = tk.Label(app, text="", font=("Helvetica", 12))
color_label.pack(pady=10)

generate_button = tk.Button(app, text="Generate Palette", command=show_palette)
generate_button.pack(pady=10)

# Show an initial palette on start
show_palette()

app.mainloop()
