gerenciarCliente.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. from tkinter import *
  2. import tkinter as tk
  3. from tkinter import ttk
  4. from tkinter import messagebox
  5. from TabClien import Clientes
  6. class tela_gerenciar_clientes():
  7. def __init__(self):
  8. self.janelaGer_Cliente = Tk()
  9. self.janelaGer_Cliente.title('Gerenciar clientes')
  10. self.janelaGer_Cliente.geometry('1600x900')
  11. self.janelaGer_Cliente.minsize(1600, 900)
  12. self.janelaGer_Cliente.maxsize(1600, 900)
  13. self.janelaGer_Cliente.config(bg="#484848")
  14. self.janelaGer_Cliente.state('zoomed')
  15. self.janelaGer_Cliente.iconbitmap('automotivo.ico')
  16. # ============= SEÇÕES ================ #
  17. self.wrapper1 = LabelFrame(
  18. self.janelaGer_Cliente, text='Clientes Cadastrados', font=("Roboto", 14, 'bold'), bg="#484848", fg="#e1e3db")
  19. self.wrapper2 = LabelFrame(
  20. self.janelaGer_Cliente, text='Procurar Cliente', font=("Roboto", 14, 'bold'), bg="#484848", fg="#e1e3db")
  21. self.wrapper3 = LabelFrame(
  22. self.janelaGer_Cliente, text='Dados do Cliente', font=("Roboto", 14, 'bold'), bg="#484848", fg="#e1e3db")
  23. self.rodape = Frame(self.janelaGer_Cliente, bg="#484848")
  24. self.wrapper1.pack(fill='both', expand='no', padx=20, pady=(20, 0))
  25. self.wrapper2.pack(fill='both', expand='no', padx=20, pady=(30, 0))
  26. self.wrapper3.pack(fill='both', expand='no', padx=20, pady=30)
  27. self.rodape.pack(fill='both', expand='no', padx=20, pady=(0, 20))
  28. # ============ SEÇÃO CLIENTES CADASTRADOS =============== #
  29. # ------------------- TREEVIEW ------------------ #
  30. self.style = ttk.Style(master=self.janelaGer_Cliente)
  31. self.style.theme_use("clam")
  32. self.style.configure("mystyle.Treeview", font=("Roboto", 14))
  33. self.style.configure("mystyle.Treeview.Heading", font=("Roboto", 16))
  34. self.style.configure("Treeview", rowheight=25)
  35. self.style.configure(
  36. "Heading", background="#4682B4", foreground="black")
  37. self.cabecalho = ('#', 'nome', 'cpf', 'carro',
  38. 'telefone', 'email', 'endereco')
  39. self.trv = ttk.Treeview(
  40. self.wrapper1, selectmode='browse', columns=self.cabecalho, show='headings')
  41. self.trv.column('#', width=20)
  42. self.trv.column('nome', width=150, anchor='center')
  43. self.trv.column('cpf', width=150)
  44. self.trv.column('carro', width=150)
  45. self.trv.column('telefone', width=150)
  46. self.trv.column('endereco', width=320)
  47. self.trv.heading('#', text='#')
  48. self.trv.heading('nome', text='Nome')
  49. self.trv.heading('cpf', text='CPF')
  50. self.trv.heading('carro', text='Carro/Placa')
  51. self.trv.heading('telefone', text='Telefone')
  52. self.trv.heading('email', text='E-mail')
  53. self.trv.heading('endereco', text='Endereço')
  54. self.trv.bind('<Double 1>', self.pegar_linha)
  55. self.trv.pack(pady=10)
  56. self.popular()
  57. # ============= SEÇÃO PROCURAR =========== #
  58. # ---------- LABELS & ENTRYS ----------- #
  59. self.lbl1 = Label(self.wrapper2, text='Palavra-Chave',
  60. bg="#484848", fg="#e1e3db")
  61. self.lbl1.pack(side='left', padx=10, pady=10)
  62. self.busca = Entry(self.wrapper2)
  63. self.busca.pack(side='left', padx=6, pady=10, ipadx=15)
  64. # ------------- BOTÃO ------------- #
  65. self.procurarBtn = Button(
  66. self.wrapper2, text='Procurar', command=self.procurar, bg="#484848", fg="#e1e3db")
  67. self.procurarBtn.pack(side='left', padx=6, pady=10, ipadx=20)
  68. self.limparBtn = Button(self.wrapper2, text=(
  69. 'Limpar'), command=self.limpar, bg="#484848", fg="#e1e3db", relief=RAISED)
  70. self.limparBtn.pack(side='left', padx=6, pady=10, ipadx=20)
  71. self.mostrarBtn = Button(
  72. self.wrapper2, padx=30, text='Mostrar Todos', command=self.popular, bg="#484848", fg="#e1e3db", relief=RAISED)
  73. self.mostrarBtn.pack(side='left', pady=10)
  74. # ========= SEÇÃO DADOS DO CLIENTE ======= #
  75. # ---------- LABELS & ENTRYS ----------- #
  76. self.lbl2 = Label(self.wrapper3, text='Nome',
  77. bg="#484848", fg="#e1e3db")
  78. self.lbl2.grid(row=0, column=0, padx=5, pady=3)
  79. self.ent2 = Entry(self.wrapper3)
  80. self.ent2.grid(row=0, column=1, padx=5, pady=3)
  81. self.lbl3 = Label(self.wrapper3, text='CPF',
  82. bg="#484848", fg="#e1e3db")
  83. self.lbl3.grid(row=1, column=0, padx=5, pady=3)
  84. self.ent3 = Entry(self.wrapper3)
  85. self.ent3.grid(row=1, column=1, padx=5, pady=3)
  86. self.lbl4 = Label(self.wrapper3, text='Carro/Placa',
  87. bg="#484848", fg="#e1e3db")
  88. self.lbl4.grid(row=2, column=0, padx=5, pady=3)
  89. self.ent4 = Entry(self.wrapper3)
  90. self.ent4.grid(row=2, column=1, padx=5, pady=3)
  91. self.lbl5 = Label(self.wrapper3, text='Telefone',
  92. bg="#484848", fg="#e1e3db")
  93. self.lbl5.grid(row=3, column=0, padx=5, pady=3)
  94. self.ent5 = Entry(self.wrapper3)
  95. self.ent5.grid(row=3, column=1, padx=5, pady=3)
  96. self.lbl6 = Label(self.wrapper3, text='E-mail',
  97. bg="#484848", fg="#e1e3db")
  98. self.lbl6.grid(row=0, column=2, padx=5, pady=3)
  99. self.ent6 = Entry(self.wrapper3)
  100. self.ent6.grid(row=0, column=3, padx=5, pady=3, ipadx=40)
  101. self.lbl7 = Label(self.wrapper3, text='Endereço',
  102. bg="#484848", fg="#e1e3db")
  103. self.lbl7.grid(row=1, column=2, padx=5, pady=3)
  104. self.ent7 = Entry(self.wrapper3)
  105. self.ent7.grid(row=1, column=3, padx=5, pady=3, ipadx=40)
  106. self.lbl8 = Label(self.wrapper3, text='ID Cliente',
  107. bg="#484848", fg="#e1e3db")
  108. self.lbl8.grid(row=2, column=2, padx=5, pady=3)
  109. self.ent8 = Entry(self.wrapper3)
  110. self.ent8.grid(row=2, column=3, padx=5, pady=3, sticky='W')
  111. # ------------ BOTÕES -------------- #
  112. self.addBtn = Button(self.wrapper3, text='Adicionar', bg="#484848", relief=RAISED, fg="#e1e3db",
  113. command=self.inserir_cliente)
  114. self.alterarBtn = Button(
  115. self.wrapper3, text='Alterar', command=self.alterar_cliente, relief=RAISED, bg="#484848", fg="#e1e3db")
  116. self.excluirBtn = Button(
  117. self.wrapper3, text='Excluir', command=self.excluir_cliente, relief=RAISED, bg="#484848", fg="#e1e3db")
  118. self.addBtn.grid(row=4, column=0, padx=5, pady=15, ipadx=25)
  119. self.alterarBtn.grid(row=4, column=1, padx=2, pady=15, ipadx=20)
  120. self.excluirBtn.grid(row=4, column=2, padx=2, pady=15, ipadx=25)
  121. self.alterarBtn.bind("<Enter>", self.hoverIn3)
  122. self.alterarBtn.bind("<Leave>", self.hoverOut)
  123. self.excluirBtn.bind("<Enter>", self.hoverIn2)
  124. self.excluirBtn.bind("<Leave>", self.hoverOut)
  125. self.addBtn.bind("<Enter>", self.hoverIn)
  126. self.addBtn.bind("<Leave>", self.hoverOut)
  127. # ========= SEÇÃO RODAPÉ ======= #
  128. # ---------- BOTÃO ----------- #
  129. self.voltarBtn = Button(
  130. self.rodape, text='Voltar', width='20', command=self.voltar_tela, relief=RAISED, bg="#484848", fg="#e1e3db")
  131. self.voltarBtn.pack(side='right')
  132. mainloop()
  133. # ============= FUNÇÕES ============== #
  134. def pegar_linha(self, identificador):
  135. customer = Clientes()
  136. self.limpar_caixas()
  137. for item in self.trv.selection():
  138. self.id = self.trv.item(item, 'values')
  139. identificador = self.id[0]
  140. customer.identificar_linha(identificador)
  141. self.ent8.insert(INSERT, customer.idcliente)
  142. self.ent2.insert(INSERT, customer.nome)
  143. self.ent3.insert(INSERT, customer.cpf)
  144. self.ent4.insert(INSERT, customer.carro)
  145. self.ent5.insert(INSERT, customer.telefone)
  146. self.ent6.insert(INSERT, customer.email)
  147. self.ent7.insert(INSERT, customer.endereco)
  148. self.leitura_apenas()
  149. def limpar_caixas(self):
  150. self.normal()
  151. self.ent2.delete(0, END)
  152. self.ent3.delete(0, END)
  153. self.ent4.delete(0, END)
  154. self.ent5.delete(0, END)
  155. self.ent6.delete(0, END)
  156. self.ent7.delete(0, END)
  157. self.ent8.delete(0, END)
  158. def procurar(self):
  159. self.trv.delete(*self.trv.get_children())
  160. customer = Clientes()
  161. nome = self.busca.get()
  162. for i in customer.filtrar_cliente(nome):
  163. self.trv.insert('', 'end', values=i)
  164. def limpar(self):
  165. self.normal()
  166. self.busca.delete(0, END)
  167. self.ent2.delete(0, END)
  168. self.ent3.delete(0, END)
  169. self.ent4.delete(0, END)
  170. self.ent5.delete(0, END)
  171. self.ent6.delete(0, END)
  172. self.ent7.delete(0, END)
  173. self.ent8.delete(0, END)
  174. def inserir_cliente(self):
  175. customer = Clientes()
  176. customer.nome = self.ent2.get()
  177. customer.cpf = self.ent3.get()
  178. customer.carro = self.ent4.get()
  179. customer.telefone = self.ent5.get()
  180. customer.email = self.ent6.get()
  181. customer.endereco = self.ent7.get()
  182. customer.add_cliente()
  183. self.popular()
  184. self.limpar_caixas()
  185. def alterar_cliente(self):
  186. customer = Clientes()
  187. customer.nome = self.ent2.get()
  188. customer.cpf = self.ent3.get()
  189. customer.carro = self.ent4.get()
  190. customer.telefone = self.ent5.get()
  191. customer.email = self.ent6.get()
  192. customer.endereco = self.ent7.get()
  193. customer.idcliente = self.ent8.get()
  194. customer.atualizar_cliente()
  195. self.popular()
  196. self.limpar_caixas()
  197. def excluir_cliente(self):
  198. customer = Clientes()
  199. customer.idcliente = self.ent8.get()
  200. customer.deletar_cliente()
  201. self.popular()
  202. self.limpar_caixas()
  203. def voltar_tela(self):
  204. self.janelaGer_Cliente.destroy()
  205. return
  206. def popular(self):
  207. self.trv.delete(*self.trv.get_children())
  208. costumer = Clientes()
  209. for i in costumer.populate():
  210. self.trv.insert('', 'end', values=i)
  211. def leitura_apenas(self):
  212. self.ent8.configure(state='disabled')
  213. def normal(self):
  214. self.ent8.configure(state='normal')
  215. def hoverIn(self, event):
  216. event.widget.config(bg="#1E90FF", fg="white", relief=GROOVE)
  217. def hoverIn2(self, event):
  218. event.widget.config(bg="#FF0000", fg="white", relief=GROOVE)
  219. def hoverIn3(self, event):
  220. event.widget.config(bg="#FFD700", fg="black", relief=GROOVE)
  221. def hoverOut(self, event):
  222. event.widget.config(bg="#484848", fg="white", relief=RAISED)
  223. minhaTela = tela_gerenciar_clientes()