-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
145 lines (116 loc) · 6.04 KB
/
app.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
import customtkinter as ctk
from tkinter import *
from tkinter import messagebox
import openpyxl
import pathlib
from openpyxl import Workbook
# Setando a aparencia padrão do sistema
ctk.set_appearance_mode("System")
ctk.set_default_color_theme("blue")
class App(ctk.CTk):
def __init__(self):
super().__init__()
self.layout_config()
self.appearence()
self.todo_sistema()
self.create_widgets() # Chama a função para criar os widgets
def layout_config(self):
self.title("Sistema de Gestão de Clientes")
self.geometry("700x500")
def appearence(self):
self.lb_apm = ctk.CTkLabel(self, text="Tema", bg_color="transparent", text_color=["#000", "#fff"])
self.lb_apm.place(x=50, y=430)
self.opt_apm = ctk.CTkOptionMenu(self, values=["System", "Dark", "Light"], command=self.change_apm)
self.opt_apm.place(x=50, y=460)
def create_widgets(self):
# texts variables
self.name_value = StringVar()
self.contact_value = StringVar()
self.age_value = StringVar()
self.address_value = StringVar()
# entrys
self.name_entry = ctk.CTkEntry(self, width=350, textvariable=self.name_value, font=("Century Gothic bold", 16), fg_color="transparent")
self.contact_entry = ctk.CTkEntry(self, width=200, textvariable=self.contact_value, font=("Century Gothic bold", 16), fg_color="transparent")
self.age_entry = ctk.CTkEntry(self, width=150, textvariable=self.age_value, font=("Century Gothic bold", 16), fg_color="transparent")
self.address_entry = ctk.CTkEntry(self, width=200, textvariable=self.address_value, font=("Century Gothic bold", 16), fg_color="transparent")
# combobox
self.gender_combobox = ctk.CTkComboBox(self, values=["Masculino", "Feminino"], font=("Century Gothic bold", 14))
self.gender_combobox.set("Masculino")
# entrada de observações
self.obs_entry = ctk.CTkTextbox(self, width=470, height=150, font=("arial", 18), border_color="#aaa", border_width=2, fg_color="transparent")
# labels
self.lb_name = ctk.CTkLabel(self, text="Nome Completo:", font=("Century Gothic bold", 16), text_color=["#000", "#fff"])
self.lb_contact = ctk.CTkLabel(self, text="Contato:", font=("Century Gothic bold", 16), text_color=["#000", "#fff"])
self.lb_age = ctk.CTkLabel(self, text="Idade:", font=("Century Gothic bold", 16), text_color=["#000", "#fff"])
self.lb_gender = ctk.CTkLabel(self, text="Gênero:", font=("Century Gothic bold", 16), text_color=["#000", "#fff"])
self.lb_address = ctk.CTkLabel(self, text="Endereço:", font=("Century Gothic bold", 16), text_color=["#000", "#fff"])
self.lb_obs = ctk.CTkLabel(self, text="Observações:", font=("Century Gothic bold", 16), text_color=["#000", "#fff"])
# posicionando os elementos na janela
self.lb_name.place(x=50, y=120)
self.name_entry.place(x=50, y=150)
self.lb_contact.place(x=450, y=120)
self.contact_entry.place(x=450, y=150)
self.lb_age.place(x=300, y=190)
self.age_entry.place(x=300, y=220)
self.lb_gender.place(x=500, y=190)
self.gender_combobox.place(x=500, y=220)
self.lb_address.place(x=50, y=190)
self.address_entry.place(x=50, y=220)
self.lb_obs.place(x=50, y=260)
self.obs_entry.place(x=180, y=260)
# Botões
btn_submit = ctk.CTkButton(self, text="Salvar dados".upper(), command=self.submit, fg_color="#151", hover_color="#131")
btn_submit.place(x=300, y=420)
btn_clear = ctk.CTkButton(self, text="Limpar Campos".upper(), command=self.clear, fg_color="#555", hover_color="#333")
btn_clear.place(x=500, y=420)
def todo_sistema(self):
frame = ctk.CTkFrame(self, width=700, height=50, corner_radius=0, bg_color="teal", fg_color="teal")
frame.place(x=0, y=10)
title = ctk.CTkLabel(frame, text="Sistema de Gestão de Clientes", font=("Century Gothic bold", 24), text_color="#fff")
title.place(x=190, y=10)
span = ctk.CTkLabel(self, text="Por favor, preencha todos os campos do formulário!", font=("Century Gothic bold", 16), text_color=["#000", "#fff"])
span.place(x=50, y=70)
def submit(self):
ficheiro = pathlib.Path("Clientes.xlsx")
if ficheiro.exists():
pass
else:
ficheiro = Workbook()
folha = ficheiro.active
folha['A1'] = "Nome Completo"
folha['B1'] = "Contato"
folha['C1'] = "Idade"
folha['D1'] = "Gênero"
folha['E1'] = "Endereço"
folha['F1'] = "Observações"
ficheiro.save("Clientes.xlsx")
name = self.name_value.get()
contact = self.contact_value.get()
age = self.age_value.get()
gender = self.gender_combobox.get()
address = self.address_value.get()
obs = self.obs_entry.get(0.0, END)
if name == "" or contact == "" or age == "" or address == "":
messagebox.showerror("Sistema", "ERRO!\nPor favor, preencha todos os campos!")
else:
ficheiro = openpyxl.load_workbook('Clientes.xlsx')
folha = ficheiro.active
folha.cell(column=1, row=folha.max_row+1, value=name)
folha.cell(column=2, row=folha.max_row, value=contact)
folha.cell(column=3, row=folha.max_row, value=age)
folha.cell(column=4, row=folha.max_row, value=gender)
folha.cell(column=5, row=folha.max_row, value=address)
folha.cell(column=6, row=folha.max_row, value=obs)
ficheiro.save(r"Clientes.xlsx")
messagebox.showinfo("Sistema", "Dados salvos com sucesso!")
def clear(self):
self.name_value.set("")
self.contact_value.set("")
self.age_value.set("")
self.address_value.set("")
self.obs_entry.delete(0.0, END)
def change_apm(self, nova_aparencia):
ctk.set_appearance_mode(nova_aparencia)
if __name__ == "__main__":
app = App()
app.mainloop()