|
| 1 | + |
| 2 | +# RGB Color Palette |
| 3 | + |
| 4 | +# imported necessary library |
| 5 | +import tkinter |
| 6 | +from tkinter import * |
| 7 | +import tkinter as tk |
| 8 | +import tkinter.messagebox as mbox |
| 9 | +from tkinter import ttk |
| 10 | +from PIL import ImageTk, Image |
| 11 | +import colorsys |
| 12 | + |
| 13 | + |
| 14 | +# Main Window & Configuration |
| 15 | +window = tk.Tk() # created a tkinter gui window frame |
| 16 | +window.title("RGB Color Palette") |
| 17 | +window.geometry('1000x700') |
| 18 | + |
| 19 | +# top label |
| 20 | +start1 = tk.Label(text="RGB COLOR PALETTE", font=("Arial", 50, "underline"), fg="magenta") # same way bg |
| 21 | +start1.place(x=120, y=10) |
| 22 | + |
| 23 | +def start_fun(): |
| 24 | + window.destroy() |
| 25 | + |
| 26 | +# start button created |
| 27 | +startb = Button(window, text="START", command=start_fun, font=("Arial", 25), bg="lightgreen", fg="blue", borderwidth=3, |
| 28 | + relief="raised") |
| 29 | +startb.place(x=130, y=580) |
| 30 | + |
| 31 | +# image on the main window |
| 32 | +path = "Images/front.png" |
| 33 | +# Creates a Tkinter-compatible photo image, which can be used everywhere Tkinter expects an image object. |
| 34 | +img1 = ImageTk.PhotoImage(Image.open(path)) |
| 35 | +# The Label widget is a standard Tkinter widget used to display a text or image on the screen. |
| 36 | +panel = tk.Label(window, image=img1) |
| 37 | +panel.place(x=210, y=100) |
| 38 | + |
| 39 | + |
| 40 | +# function created for exiting |
| 41 | +def exit_win(): |
| 42 | + if mbox.askokcancel("Exit", "Do you want to exit?"): |
| 43 | + window.destroy() |
| 44 | + |
| 45 | + |
| 46 | +# exit button created |
| 47 | +exitb = Button(window, text="EXIT", command=exit_win, font=("Arial", 25), bg="red", fg="blue", borderwidth=3, |
| 48 | + relief="raised") |
| 49 | +exitb.place(x=730, y=580) |
| 50 | +window.protocol("WM_DELETE_WINDOW", exit_win) |
| 51 | +window.mainloop() |
| 52 | + |
| 53 | +# Main Window & Configuration |
| 54 | +window1 = tk.Tk() # created a tkinter gui window frame |
| 55 | +window1.title("RGB Color Palette") |
| 56 | +window1.geometry('1000x730') |
| 57 | + |
| 58 | + |
| 59 | +# top label |
| 60 | +start1 = tk.Label(text = "RGB COLOR PALETTE", font=("Arial", 40, "underline"), fg="magenta") # same way bg |
| 61 | +start1.place(x =210, y = 10) |
| 62 | + |
| 63 | +# lbl1 = tk.Label(text="Select any video &\nconvert to grayscale video", font=("Arial", 40),fg="green") # same way bg |
| 64 | +# lbl1.place(x=170, y=110) |
| 65 | + |
| 66 | +# for preview |
| 67 | +preview_text = tk.Text(window1, height=9, width=60, font=("Arial", 15), bg="white", borderwidth=3, relief="solid") |
| 68 | +preview_text.place(x=160, y=90) |
| 69 | + |
| 70 | +# preview1 label |
| 71 | +top1 = Label(window1, text="PREVIEW AREA", font=("Arial", 40), fg="black", bg="white") # same way bg |
| 72 | +top1.place(x=270, y=130) |
| 73 | + |
| 74 | +# preview2 label |
| 75 | +top2 = Label(window1, text="Color will be previewed here...", font=("Arial", 25), fg="black",bg="white") # same way bg |
| 76 | +top2.place(x=265, y=230) |
| 77 | + |
| 78 | +Label(window1, text="RED", font=("Arial", 40), fg="red").place(x=130, y=335) |
| 79 | +Label(window1, text="GREEN", font=("Arial", 40), fg="green").place(x=130, y=415) |
| 80 | +Label(window1, text="BLUE", font=("Arial", 40), fg="blue").place(x=130, y=500) |
| 81 | + |
| 82 | +# created a scale from 1 to 10 |
| 83 | +red_scale = Scale(window1, from_=1, to=255, orient=HORIZONTAL,width = 20, length = 500, font=("Arial", 20), bg = "red", fg = "black", borderwidth=3) |
| 84 | +red_scale.place(x = 340, y = 330) |
| 85 | + |
| 86 | +# created a scale from 1 to 10 |
| 87 | +green_scale = Scale(window1, from_=1, to=255, orient=HORIZONTAL,width = 20, length = 500,font=("Arial", 20), bg = "green", fg = "black", borderwidth=3) |
| 88 | +green_scale.place(x = 340, y = 410) |
| 89 | + |
| 90 | +# created a scale from 1 to 10 |
| 91 | +blue_scale = Scale(window1, from_=1, to=255, orient=HORIZONTAL,width = 20, length = 500,font=("Arial", 20), bg = "blue", fg = "black", borderwidth=3) |
| 92 | +blue_scale.place(x = 340, y = 490) |
| 93 | + |
| 94 | +Label(window1, text="Degree", font=("Arial", 35), fg="gray").place(x=70, y=580) |
| 95 | +Label(window1, text="Saturation", font=("Arial", 35), fg="gray").place(x=370, y=580) |
| 96 | +Label(window1, text="Lightness", font=("Arial", 35), fg="gray").place(x=730, y=580) |
| 97 | + |
| 98 | +d_lbl = Label(window1, font=("Arial", 35), fg="gray") |
| 99 | +d_lbl.place(x=70, y=640) |
| 100 | +s_lbl = Label(window1, font=("Arial", 35), fg="gray") |
| 101 | +s_lbl.place(x=370, y=640) |
| 102 | +l_lbl = Label(window1, font=("Arial", 35), fg="gray") |
| 103 | +l_lbl.place(x=730, y=640) |
| 104 | + |
| 105 | +def update_color(): |
| 106 | + red = int(red_scale.get()) |
| 107 | + green = int(green_scale.get()) |
| 108 | + blue = int(blue_scale.get()) |
| 109 | + x = '#%02x%02x%02x' % (red, green, blue) |
| 110 | + preview_text.configure(bg = x) |
| 111 | + # print(x) |
| 112 | + if(x=="#010101"): |
| 113 | + top1.configure(bg = x, fg = "white") |
| 114 | + top2.configure(bg = x, fg = "white") |
| 115 | + else: |
| 116 | + top1.configure(bg=x, fg = "black") |
| 117 | + top2.configure(bg=x, fg = "black") |
| 118 | + |
| 119 | + r, g, b = [x1 / 255.0 for x1 in (red, green, blue)] |
| 120 | + h, l, s = colorsys.rgb_to_hls(r, g, b) |
| 121 | + h = round(h,4) |
| 122 | + s = round(s, 4) |
| 123 | + l = round(l, 4) |
| 124 | + d_lbl.config(text = h) |
| 125 | + s_lbl.config(text=s) |
| 126 | + l_lbl.config(text=l) |
| 127 | + # print(red_scale.get(), green_scale.get(), blue_scale.get()) |
| 128 | + window1.after(1, update_color) |
| 129 | + |
| 130 | +update_color() |
| 131 | + |
| 132 | +# function for exiting |
| 133 | +def exit_win1(): |
| 134 | + if mbox.askokcancel("Exit", "Do you want to exit?"): |
| 135 | + window1.destroy() |
| 136 | + |
| 137 | +# # Get Images Button |
| 138 | +# getb=Button(window1, text="EXIT",command=exit_win1, font=("Arial", 25), bg = "red", fg = "blue") |
| 139 | +# getb.place(x = 750, y = 580) |
| 140 | + |
| 141 | +window1.protocol("WM_DELETE_WINDOW", exit_win1) |
| 142 | +window1.mainloop() |
0 commit comments