Sunday, September 17, 2023

Comapnion_App

 The second app is done, very much modelled on the first. It takes

a hex value and returns an rgb:


                                                     




The code:

                                                                           

                  


# The window specs.
import tkinter as tk
from tkinter import*
root = Tk()
root.title('Rgb Conversion')
root.geometry("600x400")
root.configure(bg='#AA97B8')

# The conversion function.
def hex_to_rgb():
hex_string = my_num.get()
print(hex_string)
r_hex = hex_string[1:3]
g_hex = hex_string[3:5]
b_hex = hex_string[5:7]
r = int(r_hex, 16)
g = int(g_hex, 16)
b = tuple = int(b_hex, 16)
my_res.config(text="Your number is... " f"red: {r}, green: {g}, blue: {b}")

# The reset function.
def clear_entries():
for widget in root.winfo_children():
if isinstance(widget, tk.Entry):
widget.delete(0, tk.END)
my_res.config(text=" ")
my_num.focus()

# What the app does.
my_L1 = Label(root, text='Convert from Hex to rgb', font=('Arial', 10, 'normal'))
my_L1.place(x=50, y=50)

# The entry widget for the hex number.
my_num = tk.Entry(root, width=10,font=('Arial', 10, 'normal'))
my_num.place(x=50, y=150)

# The convert button.
sub_btn=tk.Button(root, text='Convert', command=hex_to_rgb)
sub_btn.place(x=50, y=250)

# The reset button.
reset_btn = tk.Button(root, text="RESET", command=clear_entries)
reset_btn.place(x=200, y=250)

# The result of the operation.
my_res = tk.Label(root, width=60, text="", font=('Arial', 10, 'normal'))
my_res.place(x=50, y=350)

# Keeping the window open,
root.mainloop()

No comments: