-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import customtkinter as ctk | ||
import matplotlib | ||
from customtkinter import filedialog | ||
import matplotlib.pyplot as plt | ||
from colorthief import ColorThief | ||
|
||
matplotlib.use('TkAgg') | ||
ctk.set_appearance_mode("dark") | ||
ctk.set_default_color_theme("dark-blue") | ||
|
||
|
||
# Function to select the image for color extraction | ||
def select_image(): | ||
try: | ||
global selected_image | ||
selected_image = filedialog.askopenfilename(filetypes=[("Image Files", "*.jpg;*.jpeg;*.png")]) | ||
ct = ColorThief(selected_image) | ||
dominant_color = ct.get_color(quality=1) | ||
status_label.configure(text="RGB: " + str(dominant_color)) | ||
plt.imshow([[dominant_color]]) | ||
plt.show() | ||
except Exception as e: | ||
print(f"Error: {str(e)}") | ||
|
||
|
||
# Global variable to store the selected image path | ||
selected_image = None | ||
|
||
# Create the main customtkinter window | ||
root = ctk.CTk() | ||
root.title("Dominant Color Extractor") | ||
root.geometry("375x130") | ||
root.resizable(False, False) | ||
|
||
frame = ctk.CTkFrame(master=root) | ||
frame.pack(pady=10, padx=10, fill="both", expand=True) | ||
|
||
select_button = ctk.CTkButton(master=frame, text="Select Image", command=select_image) | ||
select_button.pack(pady=20, padx=10) | ||
|
||
status_label = ctk.CTkLabel(master=frame, text="Please select an image.") | ||
status_label.pack(pady=5, padx=10) | ||
|
||
|
||
root.mainloop() |