cadastrarCliente.py 10 KB

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