Skip to content

Commit 52587ac

Browse files
authored
Create Random-Color-Generator.py
1 parent b9ac220 commit 52587ac

1 file changed

Lines changed: 178 additions & 0 deletions

File tree

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
import sys
2+
import os
3+
import tkinter as tk
4+
from tkinter import messagebox
5+
import random
6+
import colorsys
7+
8+
# =========================
9+
# THEME
10+
# =========================
11+
APP_BG = "#121212"
12+
PANEL_BG = "#1F1F1F"
13+
BTN_BG = "#2C2C2C"
14+
ACCENT = "#FF6F61"
15+
TEXT_CLR = "#E0E0E0"
16+
SUBTEXT_CLR = "#AAAAAA"
17+
INPUT_BG = "#333333"
18+
INPUT_FG = "#FFFFFF"
19+
20+
FONT = ("Segoe UI", 11)
21+
22+
# =========================
23+
# APP
24+
# =========================
25+
class RandomColorGeneratorApp:
26+
def __init__(self, root):
27+
self.root = root
28+
root.title("MateTools – Pro Random Color Generator")
29+
root.geometry("1000x620")
30+
root.configure(bg=APP_BG)
31+
root.resizable(False, False)
32+
33+
# =========================
34+
# LEFT PANEL
35+
# =========================
36+
left = tk.Frame(root, bg=PANEL_BG, width=420)
37+
left.pack(side="left", fill="y")
38+
39+
header = tk.Frame(left, bg=PANEL_BG)
40+
header.pack(fill="x", padx=16, pady=(18, 10))
41+
42+
tk.Label(
43+
header,
44+
text="MateTools",
45+
bg=PANEL_BG,
46+
fg=ACCENT,
47+
font=("Segoe UI", 20, "bold")
48+
).pack(side="left")
49+
50+
tk.Frame(left, bg=ACCENT, height=2).pack(fill="x", padx=16, pady=(0, 14))
51+
52+
tk.Label(
53+
left,
54+
text="Pro Random Color Generator",
55+
bg=PANEL_BG,
56+
fg=TEXT_CLR,
57+
font=("Segoe UI", 14, "bold")
58+
).pack(anchor="w", padx=16, pady=(0, 2))
59+
60+
tk.Label(
61+
left,
62+
text="Generate random colors and copy values",
63+
bg=PANEL_BG,
64+
fg=SUBTEXT_CLR,
65+
font=("Segoe UI", 10)
66+
).pack(anchor="w", padx=16, pady=(0, 16))
67+
68+
tk.Frame(left, bg=BTN_BG, height=1).pack(fill="x", padx=16, pady=(0, 16))
69+
70+
# =========================
71+
# BUTTONS
72+
# =========================
73+
btn_frame = tk.Frame(left, bg=PANEL_BG)
74+
btn_frame.pack(fill="x", padx=16, pady=16)
75+
76+
def make_btn(text, cmd, color=BTN_BG):
77+
return tk.Button(
78+
btn_frame,
79+
text=text,
80+
command=cmd,
81+
bg=color,
82+
fg="white",
83+
font=("Segoe UI", 11, "bold"),
84+
relief="flat",
85+
height=2,
86+
width=20
87+
)
88+
89+
make_btn("Generate Random Color", self.generate_color, ACCENT).pack(side="top", pady=8)
90+
make_btn("Copy HEX", self.copy_hex, BTN_BG).pack(side="top", pady=8)
91+
make_btn("Copy RGB", self.copy_rgb, BTN_BG).pack(side="top", pady=8)
92+
make_btn("Copy HSL", self.copy_hsl, BTN_BG).pack(side="top", pady=8)
93+
make_btn("About", self.show_about, BTN_BG).pack(side="top", pady=20)
94+
95+
# =========================
96+
# RIGHT PANEL
97+
# =========================
98+
right = tk.Frame(root, bg=APP_BG)
99+
right.pack(side="right", fill="both", expand=True)
100+
101+
self.result_card = tk.Frame(right, bg=PANEL_BG)
102+
self.result_card.pack(padx=30, pady=40, fill="both", expand=True)
103+
104+
tk.Label(
105+
self.result_card,
106+
text="Color Preview",
107+
bg=PANEL_BG,
108+
fg=TEXT_CLR,
109+
font=("Segoe UI", 16, "bold")
110+
).pack(pady=(20, 10))
111+
112+
self.color_preview = tk.Frame(self.result_card, bg="#333333", width=300, height=200)
113+
self.color_preview.pack(pady=(10, 20))
114+
self.color_preview.pack_propagate(False)
115+
116+
# Color values display
117+
self.hex_label = tk.Label(self.result_card, text="HEX: --", bg=PANEL_BG, fg=ACCENT, font=("Segoe UI", 14, "bold"))
118+
self.hex_label.pack(pady=5)
119+
120+
self.rgb_label = tk.Label(self.result_card, text="RGB: --", bg=PANEL_BG, fg=TEXT_CLR, font=("Segoe UI", 14, "bold"))
121+
self.rgb_label.pack(pady=5)
122+
123+
self.hsl_label = tk.Label(self.result_card, text="HSL: --", bg=PANEL_BG, fg=SUBTEXT_CLR, font=("Segoe UI", 14, "bold"))
124+
self.hsl_label.pack(pady=5)
125+
126+
# Store current color
127+
self.current_color = "#FFFFFF"
128+
129+
# =========================
130+
# METHODS
131+
# =========================
132+
def generate_color(self):
133+
r = random.randint(0, 255)
134+
g = random.randint(0, 255)
135+
b = random.randint(0, 255)
136+
self.current_color = f"#{r:02X}{g:02X}{b:02X}"
137+
h, l, s = colorsys.rgb_to_hls(r/255, g/255, b/255)
138+
hsl_str = f"{int(h*360)}, {int(s*100)}%, {int(l*100)}%"
139+
140+
self.color_preview.config(bg=self.current_color)
141+
self.hex_label.config(text=f"HEX: {self.current_color}")
142+
self.rgb_label.config(text=f"RGB: {r}, {g}, {b}")
143+
self.hsl_label.config(text=f"HSL: {hsl_str}")
144+
145+
def copy_hex(self):
146+
self.root.clipboard_clear()
147+
self.root.clipboard_append(self.current_color)
148+
messagebox.showinfo("Copied", f"{self.current_color} copied to clipboard!")
149+
150+
def copy_rgb(self):
151+
rgb_text = self.rgb_label.cget("text").replace("RGB: ", "")
152+
self.root.clipboard_clear()
153+
self.root.clipboard_append(rgb_text)
154+
messagebox.showinfo("Copied", f"{rgb_text} copied to clipboard!")
155+
156+
def copy_hsl(self):
157+
hsl_text = self.hsl_label.cget("text").replace("HSL: ", "")
158+
self.root.clipboard_clear()
159+
self.root.clipboard_append(hsl_text)
160+
messagebox.showinfo("Copied", f"{hsl_text} copied to clipboard!")
161+
162+
def show_about(self):
163+
messagebox.showinfo(
164+
"About",
165+
"MateTools – Pro Random Color Generator\n\n"
166+
"• Generate random colors instantly\n"
167+
"• View HEX, RGB, and HSL values\n"
168+
"• Copy color values to clipboard\n\n"
169+
"Built by MateTools"
170+
)
171+
172+
# =========================
173+
# RUN
174+
# =========================
175+
if __name__ == "__main__":
176+
root = tk.Tk()
177+
RandomColorGeneratorApp(root)
178+
root.mainloop()

0 commit comments

Comments
 (0)