0% found this document useful (0 votes)
7 views

Mini Project Report

Uploaded by

sohamnikam24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Mini Project Report

Uploaded by

sohamnikam24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Problem Statement: Designing a Simple Color Palette

Objective:

To leverage the Tkinter library to create an interactive color palette GUI application.
To comprehend the integration of the color selection feature within the GUI.
To implement real-time updates for the color selection and display within the palette.

Software and Hardware Used:

Operating System: Ubuntu 22.04 LTS


Development Environment: PyCharm Community Edition
Python Version: 3.3
Hardware: Dell Optiplex 3010 (Processor - Intel i3 4th Gen, Memory - 4GB)

Theory:

Tkinter Library: Python's Tkinter module facilitates the creation of Graphical User Interface
(GUI) applications, enabling an intuitive and rapid GUI development process.
Color Selection: Utilization of Tkinter for GUI design involving color selection
functionalities.
Widgets and Functions: Understanding the usage of Label widgets, color representation, and
dynamic updating within the GUI.

Algorithm:
• Import necessary modules and libraries such as Tkinter and color representation
functions.
• Set up the main Tkinter window with appropriate attributes (title, dimensions, etc.).
• Create a function to update the color palette with the selected colors.
• Utilize Tkinter's update mechanism to refresh the color palette at specified intervals.
• Define the structure and design of the color palette, including widgets for color
display and selection.
• Establish a layout that showcases the selected colors prominently.
• Incorporate functions that allow users to pick colors and dynamically update the
palette with the chosen colors.
• Implement a visual representation of the selected colors within the GUI.
• Initiate the application and execute the Tkinter event loop for continuous
responsiveness and updates.

Code:
import tkinter as tk
from tkinter import colorchooser

def add_colors():
color1 = colorchooser.askcolor(title="Choose Color 1")[1] # Get the selected color
color2 = colorchooser.askcolor(title="Choose Color 2")[1] # Get the selected color

if color1 and color2: # Check if both colors are selected


# Display the selected colors
color1_label.config(bg=color1, fg="white")
color2_label.config(bg=color2, fg="white")

# Convert colors to RGB tuples


r1, g1, b1 = tuple(int(color1[i:i+2], 16) for i in (1, 3, 5))
r2, g2, b2 = tuple(int(color2[i:i+2], 16) for i in (1, 3, 5))

# Perform color addition by averaging RGB values


r_result = (r1 + r2) // 2
g_result = (g1 + g2) // 2
b_result = (b1 + b2) // 2

# Convert the resulting RGB values to hexadecimal format


result_color = '#{:02x}{:02x}{:02x}'.format(r_result, g_result, b_result)

# Display the resulting color


result_label.config(bg=result_color, fg="white")

# Create the main window


root = tk.Tk()
root.title("Color Addition")

# Set window dimensions for a larger screen


window_width = 600
window_height = 400

# Get screen width and height to position the window at the center
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()

# Calculate X and Y position for the window to be centered


x_position = (screen_width // 2) - (window_width // 2)
y_position = (screen_height // 2) - (window_height // 2)

# Set the window geometry and position


root.geometry(f"{window_width}x{window_height}+{x_position}+{y_position}")

# Canvas to create gradient background


canvas = tk.Canvas(root, width=window_width, height=window_height,
highlightthickness=0)
canvas.pack()

# Create a gradient background


for y in range(window_height):
r = int(255 - ((255-153) * y) / window_height)
g = int(255 - ((255-0) * y) / window_height)
b = int(255 - ((255-76) * y) / window_height)
color = f'#{r:02x}{g:02x}{b:02x}'
canvas.create_line(0, y, window_width, y, fill=color)

# Labels to display selected colors with border effect


color1_label = tk.Label(root, text="Colour 1", font=8, width=19, height=5,
relief=tk.RAISED, bd=2)
color2_label = tk.Label(root, text="Colour 2", font=8, width=19, height=5,
relief=tk.RAISED, bd=2)

# Label to display the resulting color with border effect


result_label = tk.Label(root, text="Result", font=8, width=19, height=5, relief=tk.RAISED,
bd=2)

# Create a themed button to trigger color selection and addition


add_button = tk.Button(root, text="Choose Colours", font=8, command=add_colors,
width=18, height=4,bd=6)
add_button.place(relx=0.5, rely=0.48, anchor=tk.CENTER)

# Place the labels on the window


color1_label.place(relx=0.2, rely=0.2, anchor=tk.CENTER)
color2_label.place(relx=0.8, rely=0.2, anchor=tk.CENTER)
result_label.place(relx=0.5, rely=0.8, anchor=tk.CENTER)

# Start the main loop


root.mainloop()

Conclusion:
• Mastery over Tkinter library and its integration into GUI design.
• Insight into real-time color representation and updating mechanisms within a
graphical interface.
• Application of Python functionalities to develop an interactive color palette tool.

You might also like