-
Notifications
You must be signed in to change notification settings - Fork 1
/
GUI.py
174 lines (145 loc) · 4.76 KB
/
GUI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import tkinter as tk
from tkinter import ttk, messagebox
import json
from ttkthemes import ThemedTk
from PIL import Image, ImageTk
import customtkinter as ctk
class ContactFlowGUI:
def __init__(self):
self.window = ThemedTk(theme="arc") # Modern theme
self.window.title("ContactFlow")
self.window.geometry("800x600")
self.window.configure(bg="#f0f0f0")
# Initialize store
self.store = []
self.load_contacts()
# Create main containers
self.create_header()
self.create_sidebar()
self.create_main_content()
def create_header(self):
# Header frame
header = tk.Frame(self.window, bg="#2c3e50", height=60)
header.pack(fill='x')
# App title
title = tk.Label(
header,
text="ContactFlow",
font=("Helvetica", 20, "bold"),
bg="#2c3e50",
fg="white"
)
title.pack(pady=10)
def create_sidebar(self):
# Sidebar for actions
sidebar = tk.Frame(self.window, bg="#34495e", width=200)
sidebar.pack(side='left', fill='y')
# Action buttons
actions = [
("Add Contact", self.show_add_contact),
("View Contacts", self.show_contacts),
("Search", self.show_search),
("Settings", self.show_settings)
]
for text, command in actions:
btn = ctk.CTkButton(
sidebar,
text=text,
command=command,
width=180,
height=40,
corner_radius=10,
fg_color="#3498db",
hover_color="#2980b9"
)
btn.pack(pady=10, padx=10)
def create_main_content(self):
# Main content area
self.main_content = tk.Frame(self.window, bg="#f0f0f0")
self.main_content.pack(side='right', fill='both', expand=True)
# Welcome message
welcome = tk.Label(
self.main_content,
text="Welcome to ContactFlow",
font=("Helvetica", 24),
bg="#f0f0f0"
)
welcome.pack(pady=50)
def show_add_contact(self):
# Clear main content
for widget in self.main_content.winfo_children():
widget.destroy()
# Create form
form_frame = tk.Frame(self.main_content, bg="#f0f0f0")
form_frame.pack(pady=50)
fields = ["Name", "Phone", "Email"]
entries = []
for field in fields:
tk.Label(
form_frame,
text=field,
font=("Helvetica", 12),
bg="#f0f0f0"
).pack(pady=5)
entry = ctk.CTkEntry(
form_frame,
width=300,
height=35,
corner_radius=10
)
entry.pack(pady=5)
entries.append(entry)
# Save button
save_btn = ctk.CTkButton(
form_frame,
text="Save Contact",
command=lambda: self.save_contact(entries),
width=200,
height=40,
corner_radius=10,
fg_color="#27ae60",
hover_color="#219a52"
)
save_btn.pack(pady=20)
def show_contacts(self):
# Clear main content
for widget in self.main_content.winfo_children():
widget.destroy()
# Create contacts list
list_frame = tk.Frame(self.main_content, bg="#f0f0f0")
list_frame.pack(pady=20, fill='both', expand=True)
# Contacts table
columns = ("Name", "Phone", "Email")
tree = ttk.Treeview(list_frame, columns=columns, show='headings')
for col in columns:
tree.heading(col, text=col)
tree.column(col, width=200)
for contact in self.store:
tree.insert("", "end", values=contact)
tree.pack(pady=20, padx=20)
def save_contact(self, entries):
contact = [entry.get() for entry in entries]
self.store.append(contact)
self.save_contacts()
messagebox.showinfo("Success", "Contact saved successfully!")
self.show_contacts()
def load_contacts(self):
try:
with open("contacts.json", "r") as file:
self.store = json.load(file)
except FileNotFoundError:
self.store = []
def save_contacts(self):
with open("contacts.json", "w") as file:
json.dump(self.store, file)
def show_search(self):
# Implement search functionality
pass
def show_settings(self):
# Implement settings functionality
pass
def run(self):
self.window.mainloop()
if __name__ == "__main__":
app = ContactFlowGUI()
app.run()