cadastrarFuncionario.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. from tkinter import *
  2. import tkinter as tk
  3. from tkinter import ttk
  4. from tkinter import messagebox
  5. from tkinter.font import BOLD
  6. from turtle import width
  7. from TabFunc import TabFunc
  8. class ver_cadastrar_func():
  9. def __init__(self):
  10. self.janela = Tk()
  11. self.janela.title('Cadastro de Funcionários')
  12. self.janela.geometry('1600x900')
  13. self.janela.minsize(1600, 900)
  14. self.janela.maxsize(1600, 900)
  15. self.janela.config(bg="#484848")
  16. self.janela.state("zoomed")
  17. self.janela.iconbitmap('automotivo.ico')
  18. #self.janela.attribute('-fullscreen', True)
  19. # ============= SEÇÕES ================ #
  20. self.container1 = LabelFrame(self.janela, bg="#484848", fg="#e1e3db")
  21. self.wrapper1 = LabelFrame(
  22. self.container1, text='Dados do Funcionário', font=("Roboto", 18, 'bold'), bg="#484848", fg="#e1e3db")
  23. self.wrapper2 = LabelFrame(
  24. self.janela, text='Funcionários', font=("Roboto", 18, 'bold'), bg="#484848", fg="#e1e3db")
  25. self.wrapper3 = LabelFrame(
  26. self.container1, width=400, font=("Roboto", 18, 'bold'), text='Procurar', bg="#484848", fg="#e1e3db")
  27. self.rodape = Frame(self.janela, bg="#484848")
  28. self.container1.pack(fill='both', expand='no', padx=30, pady=10)
  29. self.wrapper1.pack(fill='both', expand='yes',
  30. padx=25, pady=10, ipady=30, side="left")
  31. self.wrapper2.pack(fill='none', expand='no',
  32. padx=10, pady=10)
  33. self.wrapper3.pack(fill='x', expand='no', ipadx=30,
  34. padx=30, ipady=75, side="right")
  35. self.rodape.pack(fill='both', expand='yes', padx=20)
  36. # ========= SEÇÃO DADOS DO FUNCIONÁRIO ======= #
  37. # ---------- LABELS & ENTRYS ----------- #
  38. self.labelNome = Label(self.wrapper1, font=(
  39. "Roboto", 16), text='Nome', bg="#484848", fg="#e1e3db")
  40. self.labelNome.grid(row=0, column=0, padx=5, pady=5)
  41. self.caixaNome = Entry(self.wrapper1, width=40)
  42. self.caixaNome.grid(row=0, column=1, padx=5, pady=5)
  43. self.lbl3 = Label(self.wrapper1, font=("Roboto", 16),
  44. text='CPF', bg="#484848", fg="#e1e3db")
  45. self.lbl3.grid(row=1, column=0, padx=5, pady=3)
  46. self.caixaCPF = Entry(self.wrapper1, width=40)
  47. self.caixaCPF.grid(row=1, column=1, padx=5, pady=5)
  48. self.lbl4 = Label(self.wrapper1, font=("Roboto", 16),
  49. text='Cargo', bg="#484848", fg="white")
  50. self.lbl4.grid(row=2, column=0, padx=5, pady=3)
  51. self.caixaCargo = Entry(self.wrapper1, width=40)
  52. self.caixaCargo.grid(row=2, column=1, padx=5, pady=5)
  53. self.lbl5 = Label(self.wrapper1, font=("Roboto", 16),
  54. text='Login', bg="#484848", fg="#e1e3db")
  55. self.lbl5.grid(row=0, column=2, padx=50, pady=5)
  56. self.caixaLogin = Entry(self.wrapper1)
  57. self.caixaLogin.grid(row=0, column=3, padx=5, pady=5)
  58. self.lbl6 = Label(self.wrapper1, font=("Roboto", 16),
  59. text='Senha', bg="#484848", fg="#e1e3db")
  60. self.lbl6.grid(row=1, column=2, padx=5, pady=5)
  61. self.caixaSenha = Entry(self.wrapper1)
  62. self.caixaSenha.grid(row=1, column=3, padx=5, pady=5)
  63. self.lbl7 = Label(self.wrapper1, font=("Roboto", 16),
  64. text='ID Funcionário', bg="#484848", fg="#e1e3db")
  65. self.lbl7.grid(row=2, column=2, padx=5, pady=5)
  66. self.caixaId = Entry(self.wrapper1)
  67. self.caixaId.grid(row=2, column=3, padx=10, pady=5, sticky='W')
  68. # ------------ BOTÕES -------------- #
  69. self.addBtn = Button(self.wrapper1, text='Adicionar', font=("Roboto", 16),
  70. command=self.inserir_func, bg="#566981", fg="#e1e3db", relief=RAISED)
  71. self.addBtn.bind("<Enter>", self.hoverIn1)
  72. self.addBtn.bind("<Leave>", self.hoverOut)
  73. self.alterarBtn = Button(
  74. self.wrapper1, text='Alterar', font=("Roboto", 16), command=self.alterar_func, bg="#566981", fg="#e1e3db", relief=RAISED)
  75. self.alterarBtn .bind("<Enter>", self.hoverIn4)
  76. self.alterarBtn .bind("<Leave>", self.hoverOut)
  77. self.excluirBtn = Button(
  78. self.wrapper1, text='Excluir', font=("Roboto", 16), command=self.excluir_func, bg="#566981", fg="#e1e3db", relief=RAISED)
  79. self.excluirBtn.bind("<Enter>", self.hoverIn3)
  80. self.excluirBtn.bind("<Leave>", self.hoverOut)
  81. self.addBtn.grid(row=4, column=1, padx=5, pady=10, ipadx=25)
  82. self.alterarBtn.grid(row=4, column=2, padx=5, pady=3, ipadx=20)
  83. self.excluirBtn.grid(row=4, column=3, padx=5, pady=3, ipadx=25)
  84. # ========== SEÇÃO FUNCIONÁRIOS CADASTRADOS ============ #
  85. # ------------------- TREEVIEW ------------------ #
  86. self.style = ttk.Style(master=self.janela)
  87. self.style.theme_use("clam")
  88. self.style.configure("mystyle.Treeview", font=("Roboto", 14))
  89. self.style.configure("mystyle.Treeview.Heading", font=("Roboto", 16))
  90. self.style.configure("Treeview", background="silver", rowheight=20, fieldbackground="#E0FFFF",)
  91. self.style.configure("Heading", background="#4682B4", foreground = "white")
  92. self.cabecalho = ('#', 'nome', 'cpf', 'cargo',
  93. 'login', 'senha')
  94. self.trv = ttk.Treeview(
  95. self.wrapper2, style="mystyle.Treeview", selectmode='browse', columns=self.cabecalho, show='headings')
  96. self.trv.column('#', width=30)
  97. self.trv.column('nome', anchor='center', width=350)
  98. self.trv.column('cpf', anchor='center', width=180)
  99. self.trv.column('cargo', anchor='center', width=180)
  100. self.trv.column('login', anchor='center', width=150)
  101. self.trv.column('senha', anchor='center', width=150)
  102. self.trv.heading('#', text='#')
  103. self.trv.heading('nome', text='NOME')
  104. self.trv.heading('cpf', text='CPF')
  105. self.trv.heading('cargo', text='CARGO')
  106. self.trv.heading('login', text='LOGIN')
  107. self.trv.heading('senha', text='SENHA')
  108. self.trv.bind('<Double 1>', self.pegar_linha)
  109. self.trv.pack()
  110. self.popular()
  111. # ============= SEÇÃO PROCURAR =========== #
  112. # ---------- LABELS & ENTRYS ----------- #
  113. self.lbl1 = Label(self.wrapper3, font=(
  114. "Roboto", 14), text='Palavra-Chave', bg="#566981", fg="#e1e3db", relief=RAISED)
  115. self.lbl1.pack(side='left', padx=10, pady=10, ipadx=10)
  116. self.busca = Entry(self.wrapper3)
  117. self.busca.pack(side='left', padx=6, pady=10, ipadx=10, ipady=2)
  118. # ------------- BOTÕES ------------- #
  119. self.procurarBtn = Button(
  120. self.wrapper3, text='Procurar', font=("Roboto", 14), command=self.procurar, bg="#566981", fg="#e1e3db", relief=RAISED)
  121. self.procurarBtn.pack(side='left', padx=20, pady=10, ipadx=10)
  122. self.procurarBtn.bind("<Enter>", self.hoverIn2)
  123. self.procurarBtn.bind("<Leave>", self.hoverOut)
  124. self.limparBtn = Button(
  125. self.wrapper3, text='Limpar', font=("Roboto", 14), command=self.limpar, bg="#566981", fg="#e1e3db", relief=RAISED)
  126. self.limparBtn.pack(side='left', padx=6, pady=10, ipadx=10)
  127. self.limparBtn .bind("<Enter>", self.hoverIn4)
  128. self.limparBtn .bind("<Leave>", self.hoverOut)
  129. self.mostrarBtn = Button(
  130. self.wrapper2, padx=30, text='Mostrar Todos', font=("Roboto", 16), command=self.popular, bg="#566981", fg="#e1e3db", relief=RAISED)
  131. self.mostrarBtn.pack(side='right', padx=600, pady=10)
  132. self.mostrarBtn.bind("<Enter>", self.hoverIn2)
  133. self.mostrarBtn.bind("<Leave>", self.hoverOut)
  134. # ========= SEÇÃO RODAPÉ ======= #
  135. # ---------- BOTÃO ----------- #
  136. self.voltarBtn = Button(
  137. self.rodape, text='Voltar', font=("Roboto", 12), width='15', command=self.voltar_tela, bg="#800000", fg="#e1e3db", relief=RAISED)
  138. self.voltarBtn.pack(side='right', padx=2, ipadx=2)
  139. mainloop()
  140. # ============= FUNÇÕES ============== #
  141. def pegar_linha(self, identificador):
  142. staff = TabFunc()
  143. self.normal()
  144. self.limpar_caixas()
  145. for item in self.trv.selection():
  146. self.id = self.trv.item(item, 'values')
  147. identificador = self.id[0]
  148. staff.identificar_linha(identificador)
  149. self.caixaId.insert(INSERT, staff.idfunc)
  150. self.caixaNome.insert(INSERT, staff.nome)
  151. self.caixaCPF.insert(INSERT, staff.cpf)
  152. self.caixaCargo.insert(INSERT, staff.cargo)
  153. self.caixaLogin.insert(INSERT, staff.login)
  154. self.caixaSenha.insert(INSERT, staff.senha)
  155. self.leitura_apenas()
  156. def limpar_caixas(self):
  157. self.normal()
  158. self.caixaNome.delete(0, END)
  159. self.caixaCPF.delete(0, END)
  160. self.caixaCargo.delete(0, END)
  161. self.caixaLogin.delete(0, END)
  162. self.caixaSenha.delete(0, END)
  163. self.caixaId.delete(0, END)
  164. def procurar(self):
  165. self.trv.delete(*self.trv.get_children())
  166. staff = TabFunc()
  167. nome = self.busca.get()
  168. for i in staff.filtrar_func(nome):
  169. self.trv.insert('', 'end', values=i)
  170. def limpar(self):
  171. self.normal()
  172. self.busca.delete(0, END)
  173. self.caixaNome.delete(0, END)
  174. self.caixaCPF.delete(0, END)
  175. self.caixaCargo.delete(0, END)
  176. self.caixaLogin.delete(0, END)
  177. self.caixaSenha.delete(0, END)
  178. self.caixaId.delete(0, END)
  179. def inserir_func(self):
  180. staff = TabFunc()
  181. staff.nome = self.caixaNome.get()
  182. staff.cpf = self.caixaCPF.get()
  183. staff.cargo = self.caixaCargo.get()
  184. staff.login = self.caixaLogin.get()
  185. staff.senha = self.caixaSenha.get()
  186. staff.add_func()
  187. self.popular()
  188. self.limpar_caixas()
  189. def alterar_func(self):
  190. staff = TabFunc()
  191. staff.nome = self.caixaNome.get()
  192. staff.cpf = self.caixaCPF.get()
  193. staff.cargo = self.caixaCargo.get()
  194. staff.login = self.caixaLogin.get()
  195. staff.senha = self.caixaSenha.get()
  196. staff.idfunc = self.caixaId.get()
  197. staff.atualizar_func()
  198. self.popular()
  199. self.limpar_caixas()
  200. def excluir_func(self):
  201. staff = TabFunc()
  202. staff.idfunc = self.caixaId.get()
  203. staff.deletar_func()
  204. self.popular()
  205. self.limpar_caixas()
  206. def voltar_tela(self):
  207. self.janela.destroy()
  208. return
  209. def popular(self):
  210. self.trv.delete(*self.trv.get_children())
  211. staff = TabFunc()
  212. for i in staff.populate():
  213. self.trv.insert('', 'end', values=i)
  214. def leitura_apenas(self):
  215. self.caixaId.configure(state='disabled')
  216. def normal(self):
  217. self.caixaId.configure(state='normal')
  218. def hoverIn1(self, event): # verde
  219. event.widget.config(bg="#32CD32", fg="white", relief=GROOVE)
  220. def hoverIn2(self, event): # azul
  221. event.widget.config(bg="#6495ED", fg="white", relief=GROOVE)
  222. def hoverIn3(self, event): # vermelho
  223. event.widget.config(bg="#FF0000", fg="white", relief=GROOVE)
  224. def hoverIn4(self, event): # amarelo
  225. event.widget.config(bg="#FFD700", fg="white", relief=GROOVE)
  226. def hoverOut(self, event):
  227. event.widget.config(bg="#566981", fg="#e1e3db", relief=RAISED)
  228. # def startJan(self):
  229. # minhaTela = ver_cadastrar_func()
  230. # return minhaTela.janela.mainloop()
  231. minhaTela = ver_cadastrar_func()