-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproject-16.py
More file actions
31 lines (23 loc) · 972 Bytes
/
project-16.py
File metadata and controls
31 lines (23 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Project-16 :Color-Pick
# Codesphered01010
import tkinter as tk
from tkinter import colorchooser
def pick_color():
color_code = colorchooser.askcolor(title="Pilih Warna")[1]
if color_code:
color_label.config(text=f"Warna: {color_code}", bg=color_code, fg="white" if is_dark_color(color_code) else "black")
def is_dark_color(hex_color):
hex_color = hex_color.lstrip("#")
r, g, b = tuple(int(hex_color[i:i+2], 16) for i in (0, 2, 4))
brightness = (r*299 + g*587 + b*114) / 1000
return brightness < 128
root = tk.Tk()
root.title("Color Picker")
root.geometry("300x150")
instruction_label = tk.Label(root, text="Klik tombol untuk memilih warna:")
instruction_label.pack(pady=10)
color_button = tk.Button(root, text="Pilih Warna", command=pick_color)
color_button.pack(pady=10)
color_label = tk.Label(root, text="Warna: #FFFFFF", bg="white", width=30, height=2)
color_label.pack(pady=10)
root.mainloop()