Saturday, September 9, 2023

OPACITY

 New day; been tweaking the Opacity app:

Using submit:

                                                               




Using reset:



The code:  
import tkinter as tk

root = tk.Tk()
root.configure(bg='silver')
root.title('OPACITY')

# setting the windows size
root.geometry("600x400")

# declaring variables
# for storing code and opacity
red_var = tk.IntVar(value="")
green_var = tk.IntVar(value="")
blue_var = tk.IntVar(value="")
opacity_var = tk.DoubleVar(value="")

res_red = ""
res_green = ""
res_blue = ""
label_res = tk.Label(root, width=30, text=" ")

# defining a function that will
# get the code and opacity.


def clear_entries():
for widget in root.winfo_children():
if isinstance(widget, tk.Entry):
widget.delete(0, tk.END)
label_res.config(text=" ")
red_entry.focus()


def submit():

opacity =(opacity_var.get())
#opacity_entry.config(state="disabled")

red = (red_var.get())
res_red = round(255 - opacity*(255 - red))
green = (green_var.get())
res_green = round(255 - opacity*(255 - green))
blue = (blue_var.get())
res_blue = round(255 - opacity*(255 - blue))

label_res.config(text="Your safe color is : " + str(res_red) + " " + str(res_green)+" "+ str(res_blue))
#label_res.config(text=f"Your safe color is: {res_red},{res_green},{res_blue}")
#print("Your safe color is: "+str(res_red)+","+str(res_green)+","+str(res_blue))
#print(f"Your safe color is: {res_red},{res_green},{res_blue}")

# creating a label for
# code using widget Label
instruction_label = tk.Label(root,text="Please enter RGBA values:")


# creating a entry for input
# channels using widget Entry
red_entry = tk.Entry(root, textvariable=red_var, font=('calibre', 10, 'normal'))
green_entry = tk.Entry(root, textvariable=green_var, font=('calibre', 10, 'normal'))
blue_entry = tk.Entry(root, textvariable=blue_var, font=('calibre', 10, 'normal'))
opacity_entry = tk.Entry(root, textvariable=opacity_var, font=('calibre', 10, 'normal'))


# creating a button using the widget
# that will call the submit function.
sub_btn = tk.Button(root, text='SUBMIT', command=submit)
clear_btn = tk.Button(root, text='RESET', command=clear_entries)

# styling the buttons

#style = tk.Style()
sub_btn.configure(background="blue", foreground="red", font=("Arial", 12, 'bold'))
clear_btn.configure(background="blue", foreground="yellow", font=("Arial", 12, 'bold'))
# placing the label and entry in
# the required position using the place
# method

instruction_label.place(x=50, y=50)
red_entry.place(x=50, y=75)
green_entry.place(x=150, y=75)
blue_entry.place(x=250, y=75)
opacity_entry.place(x=350, y=75)
sub_btn.place(x=50, y=175)
clear_btn.place(x=200, y=175)
label_res.place(x=50, y=225)

# performing an infinite loop
# for the window to display
root.mainloop()
                                                                                                                                                             
)
                                                                                *     *     *

Opacity has joined colormixer as an executable on my desktop 😄

                                                                                     

                                                                    *     *     *

There are really two syntax models available to us in outputting our result.

The one using f"" is a later one; the difference being really about what iss most

readable given the data at hand.

One can concatenate srings using the + sign.

If two different data types are at work, one uses a coma ie ,   ...

                                                                          

                                                                                   



      

                                                                                            

No comments: