Advertisement
danrleydaniel

pyfood.py

Jan 24th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 10.10 KB | None | 0 0
  1. ####BIBLIOTECAS, DICIONÁRIOS E COISAS TÉCNICAS####
  2.  
  3. from tkinter import *
  4. from datetime import datetime
  5. from random import choice
  6. import pickle
  7.  
  8. elementos = ("0", "1","2","3","4","5","6","7","8","9")
  9.  
  10. refeicoes = {}
  11. notas = {}
  12.  
  13. ####GERAÇÃO DE DATAS, ID'S E COISAS SEMELHANTES####
  14.  
  15. def dataHoje():
  16.     data = str(datetime.now())
  17.     dia = (data[8:10])
  18.     mes = (data[5:7])
  19.     ano = (data[0:4])
  20.     data = (dia + "/" + mes + "/" + ano)
  21.     return data
  22.    
  23. def id(x):
  24.     substr = (x[0:3])
  25.     substr = substr.upper()
  26.     n1 = choice(elementos)
  27.     n2 = choice(elementos)
  28.     id = "REF" + substr + n1 + n2
  29.     if id in refeicoes:
  30.         id += "1"
  31.     else:
  32.         id = id
  33.     return id
  34.  
  35.  
  36. ####FUNÇÕES TÉCNICAS####
  37. def fec():
  38.     janelaCad.quit()
  39.  
  40.  
  41. ####FUNCÕES DO PROGRAMA PRINCIPAL####
  42.  
  43. #CADASTRO DE REFEIÇÃO#
  44. def janelaCad():
  45.     def click_button():
  46.         confirm["text"] = "Refeição cadastrada."
  47.        
  48.         listaDados = []
  49.         name = str(entNom.get())
  50.         price = ("R$" + str(entPre.get()))
  51.         time = str(entTem.get())
  52.         aux = id(name)
  53.         listaDados.append(name)
  54.         listaDados.append(price)
  55.         listaDados.append(time)
  56.         listaDados.append(aux)
  57.         refeicoes[aux] = listaDados
  58.        
  59.         btfec = Button(janelaCad, width=10, text="Sair", command=fec)
  60.         btfec.place(x=85,y=500)
  61.        
  62.    
  63.     janelaCad = Tk()
  64.     janelaCad.geometry("500x500")
  65.     janelaCad.title("Cadastrar refeição")
  66.     #Definindo labels:
  67.     nom = Label(janelaCad, text="Nome: ")
  68.     pre = Label(janelaCad, text="Preço: ")
  69.     tem = Label(janelaCad, text="Tempo de preparo: ")
  70.     confirm = Label(janelaCad, text="")
  71.    
  72.     #Definindo entradas:
  73.     entNom = Entry(janelaCad)
  74.     entPre = Entry(janelaCad)
  75.     entTem = Entry(janelaCad)
  76.    
  77.     #Definindo button:
  78.     bt = Button(janelaCad, width=20, text="CADASTRAR REFEIÇÃO",command=click_button)
  79.    
  80.     #Definindo posições:
  81.     nom.place(x=50,y=50)
  82.     pre.place(x=50,y=100)
  83.     tem.place(x=50,y=150)
  84.     entNom.place(x=150,y=50)
  85.     entPre.place(x=150,y=100)
  86.     entTem.place(x=290,y=150)
  87.     bt.place(x=100,y=250)
  88.     confirm.place(x=85,y=450)
  89.    
  90.     arqRef = open("ref.dat","wb")
  91.     pickle.dump(refeicoes, arqRef)
  92.     arqRef.close()
  93.    
  94.     janelaCad.mainloop()
  95.  
  96. #CHECAR REFEIÇÕES#
  97.  
  98. def janelaRe():
  99.     janelaRe = Tk()
  100.     janelaRe.geometry("600x600")
  101.     janelaRe.title("Checar refeições")
  102.    
  103.     #Auxiliares de posicionamento
  104.     auxY = 100
  105.     auxXNom = 0
  106.     auxXPre = 200
  107.     auxXTem = 400
  108.     auxXId = 600
  109.    
  110.     #Indicadores do topo da tabela, suas cores e posições
  111.     indNome = Label(janelaRe, text="Nome                        ")
  112.     indPreco = Label(janelaRe, text="Preço                        ")
  113.     indTempo = Label(janelaRe, text="TdP                          ")
  114.     indId = Label(janelaRe, text="ID                      ")
  115.    
  116.     indNome["bg"] = "blue"
  117.     indPreco["bg"] = "blue"
  118.     indTempo["bg"] = "blue"
  119.     indId["bg"] = "blue"
  120.    
  121.     indNome.place(x=auxXNom, y=50)
  122.     indPreco.place(x=auxXPre, y=50)
  123.     indTempo.place(x=auxXTem, y=50)
  124.     indId.place(x=auxXId, y=50)
  125.    
  126.     #Percorrimento do dicionário
  127.     for i in refeicoes:
  128.         nomRef = Label(janelaRe, text=refeicoes[i][0])
  129.         preRef = Label(janelaRe, text=refeicoes[i][1])
  130.         temRef = Label(janelaRe, text=refeicoes[i][2])
  131.         idRef = Label(janelaRe, text=refeicoes[i][3])
  132.        
  133.         nomRef.place(x = auxXNom, y = auxY)
  134.         preRef.place(x = auxXPre, y = auxY)
  135.         temRef.place(x = auxXTem, y = auxY)
  136.         idRef.place(x = auxXId, y = auxY)
  137.        
  138.         auxY += 50
  139.    
  140.     janelaRe.mainloop()
  141.  
  142. #BUSCAR REFEIÇÕES#
  143.  
  144. def buscarRe():
  145.     def click_button():
  146.         #Auxiliares de posicionamento
  147.         auxY = 200
  148.         auxXNom = 0
  149.         auxXPre = 200
  150.         auxXTem = 400
  151.         auxXId = 600
  152.        
  153.         #Variável que recebe o resultado da busca:    
  154.         pesquisa = str(busca.get())
  155.        
  156.         #Indicadores do topo da tabela, suas cores e posições:       
  157.         indNome = Label(buscarRe, text="Nome                        ")
  158.         indPreco = Label(buscarRe, text="Preço                        ")
  159.         indTempo = Label(buscarRe, text="TdP                          ")
  160.         indId = Label(buscarRe, text="ID                      ")
  161.                    
  162.         indNome["bg"] = "blue"
  163.         indPreco["bg"] = "blue"
  164.         indTempo["bg"] = "blue"
  165.         indId["bg"] = "blue"
  166.                    
  167.         indNome.place(x=auxXNom, y=150)
  168.         indPreco.place(x=auxXPre, y=150)
  169.         indTempo.place(x=auxXTem, y=150)
  170.         indId.place(x=auxXId, y=150)
  171.        
  172.         #Percorrimento do dicionário com a busca aplicada:
  173.         for i in refeicoes:
  174.             if (pesquisa.upper()) in (refeicoes[i][0].upper()):
  175.                 nomRef = Label(buscarRe, text=refeicoes[i][0])
  176.                 preRef = Label(buscarRe, text=refeicoes[i][1])
  177.                 temRef = Label(buscarRe, text=refeicoes[i][2])
  178.                 idRef = Label(buscarRe, text=refeicoes[i][3])
  179.                        
  180.                 nomRef.place(x = auxXNom, y = auxY)
  181.                 preRef.place(x = auxXPre, y = auxY)
  182.                 temRef.place(x = auxXTem, y = auxY)
  183.                 idRef.place(x = auxXId, y = auxY)
  184.                        
  185.                 auxY += 50
  186.    
  187.     buscarRe = Tk()
  188.     buscarRe.geometry("700x700")
  189.     buscarRe.title("Buscar refeição")
  190.        
  191.     instr = Label(buscarRe, text="Digite o nome da refeição que está procurando: ")
  192.     instr.place(x=115, y=30)
  193.        
  194.        
  195.     busca = Entry(buscarRe)
  196.     busca.place(x=250, y=70)
  197.        
  198.        
  199.     bt = Button(buscarRe, width=20, text="PESQUISAR", command = click_button)
  200.     bt.place(x= 220, y=120)
  201.        
  202.     buscarRe.mainloop()
  203.  
  204. #DELETAR#
  205. def deletar():
  206.     #Botão que confirma a instrução:
  207.     def bt2_click():
  208.         aux = str(iden.get())
  209.         del refeicoes[aux]
  210.         aviso = Label(deletar, text="Refeição deletada com sucesso.")
  211.         aviso.place(x=400, y=575)
  212.    
  213.     #Botão que nega a instrução:
  214.     def bt3_click():
  215.         deletar.quit()
  216.    
  217.     #Comando do botão de pesquisa:
  218.     def bt1_click():
  219.         aux = str(iden.get())
  220.         if aux not in refeicoes:
  221.             aviso = Label(deletar, text="Esse ID não foi encontrado.")
  222.             aviso.place(x=250, y=275)
  223.         else:
  224.             aviso = Label(deletar, text="A seguinte refeição foi encontrada: ")
  225.             aviso.place(x=250, y=325)
  226.             aviso2 = Label(deletar, text=refeicoes[aux][0])
  227.             aviso2.place(x=250, y=375)
  228.             aviso3 = Label(deletar, text="Deseja mesmo deletá-la?")
  229.             aviso3.place(x=250, y=425)
  230.                
  231.             bt2 = Button(deletar, width = 10, text="SIM", command = bt2_click)
  232.             bt2.place(x=200, y=475)
  233.                
  234.             bt3 = Button(deletar, width = 10, text="NÃO", command = bt3_click)
  235.             bt3.place(x=400, y=475)
  236.        
  237.     deletar = Tk()
  238.     deletar.geometry("700x700")
  239.     deletar.title("Deletar")
  240.        
  241.     instr = Label(deletar, text="Digite o ID da refeição que deseja deletar: ")
  242.     instr.place(x=150, y=75)
  243.        
  244.     iden = Entry(deletar)
  245.     iden.place(x=250, y=125)
  246.        
  247.     bt1 = Button(deletar, width=20, text="PESQUISAR", command=bt1_click)
  248.     bt1.place(x=220, y=175)
  249.    
  250.     arqRef = open("ref.dat","wb")
  251.     pickle.dump(refeicoes, arqRef)
  252.     arqRef.close()
  253.    
  254.     deletar.mainloop()
  255.  
  256. #CALCULADORA#
  257. def calculadora():
  258.     #Definições das 4 operações:
  259.     def soma():
  260.         valor1 = float(vlr1.get())
  261.         valor2 = float(vlr2.get())
  262.         resultado = valor1 + valor2
  263.         lbR["bg"] = "white"
  264.         lbR["text"] = resultado
  265.    
  266.     def sub():
  267.         valor1 = float(vlr1.get())
  268.         valor2 = float(vlr2.get())
  269.         resultado = valor1 - valor2
  270.         lbR["bg"] = "white"
  271.         lbR["text"] = resultado
  272.    
  273.     def mult():
  274.         valor1 = float(vlr1.get())
  275.         valor2 = float(vlr2.get())
  276.         resultado = valor1 * valor2
  277.         lbR["bg"] = "white"
  278.         lbR["text"] = resultado
  279.    
  280.     def div():
  281.         valor1 = float(vlr1.get())
  282.         valor2 = float(vlr2.get())
  283.         if valor2 == 0:
  284.             lbR["text"] = "Você não pode dividir por 0"
  285.             lbR["foreground"] = "red"
  286.         else:
  287.             resultado = valor1 / valor2
  288.             lbR["bg"] = "white"
  289.             lbR["text"] = resultado
  290.    
  291.     calculadora = Tk()
  292.     calculadora.geometry("300x400")
  293.     calculadora.title("Calculadora")
  294.    
  295.     #Instrução dos valores:
  296.     inst1 = Label(calculadora, text="Valor 1:")
  297.     inst2 = Label(calculadora, text="Valor 2:")
  298.    
  299.     #Criação dos botões:
  300.     btSom = Button(calculadora, width=5, text="+", command = soma)
  301.     btSub = Button(calculadora, width=5, text="-", command = sub)
  302.     btMult = Button(calculadora, width=5, text="×", command = mult)
  303.     btDiv = Button(calculadora, width=5, text="÷", command = div)
  304.    
  305.     #Entrada de dados:
  306.     vlr1 = Entry(calculadora)
  307.     vlr2 = Entry(calculadora)
  308.    
  309.     #Exibição:
  310.     lbRIns = Label(calculadora, text="Resultado: ")
  311.     lbR = Label(calculadora, text="")
  312.    
  313.     #Posições:
  314.     inst1.place(x=5, y=10)
  315.     inst2.place(x=5, y=60)
  316.    
  317.     vlr1.place(x=105, y=10)
  318.     vlr2.place(x=105, y=60)
  319.    
  320.     btSom.place(x=15, y=110)
  321.     btSub.place(x=155, y=110)
  322.     btMult.place(x=15, y=170)
  323.     btDiv.place(x=155, y=170)
  324.    
  325.     lbRIns.place(x=50, y=260)
  326.     lbR.place(x=85, y=310)
  327.    
  328.    
  329.     calculadora.mainloop()
  330.  
  331. #PEDIDO#
  332. def pedido():
  333.     def button_click():
  334.         aviso = Tk()
  335.         aviso.geometry("500x500")
  336.        
  337.         aten = Label(aviso, text="Opção fazer pedido em breve")
  338.         aten.place(x=100, y=100)
  339.        
  340.         aviso.mainloop()
  341.    
  342.     pedido = Tk()
  343.     pedido.geometry("600x600")
  344.    
  345.     auxY = 100
  346.    
  347.     for i in refeicoes:
  348.         sele = Checkbutton(pedido, text=refeicoes[i][0])
  349.         sele.place(x=50, y = auxY)
  350.         auxY += 50
  351.    
  352.     bt = Button(pedido, text="FAZER PEDIDO", command = button_click)
  353.     bt.place(x=75, y=auxY)
  354.    
  355.     pedido.mainloop()
  356.  
  357. ####PROGRAMA####
  358.  
  359. try:
  360.     arqRef = open("ref.dat","rb")
  361.     refeicoes = pickle.load(arqRef)
  362.     arqRef.close()
  363. except IOError:
  364.     print()
  365.  
  366. janelaPrin = Tk()
  367. janelaPrin.geometry("800x800")
  368. janelaPrin["bg"] = "white"
  369. janelaPrin.title("Sistema do Restaurante Sertão Sabores")
  370.  
  371. #icone = PhotoImage#(file="/storage/emulated/0/Download/Calc2.png")
  372.  
  373. #imagem = PhotoImage#(file="/storage/emulated/0/Download/Imagem.png")
  374. #ima = Label(janelaPrin, image=imagem)
  375. #ima.place(x=100, y=100)
  376.  
  377. butCad = Button(janelaPrin, width = 15, text="CADASTRAR REFEIÇÃO", command = janelaCad)
  378. butCad.place(x=50, y=5)
  379.  
  380. butChe = Button(janelaPrin, width=15, text="CHECAR REFEIÇÕES", command = janelaRe)
  381. butChe.place(x=320, y=5)
  382.  
  383. butBus = Button(janelaPrin, width=15, text="BUSCAR REFEIÇÃO", command = buscarRe)
  384. butBus.place(x=590, y=5)
  385.  
  386. butDel = Button(janelaPrin, width=15, text="DELETAR REFEIÇÃO", command = deletar)
  387. butDel.place(x=500, y=100)
  388.  
  389. butPed = Button(janelaPrin, width=15, text="FAZER PEDIDO", command = pedido)
  390. butPed.place(x=500, y=180)
  391.  
  392. #butCal = Button(janelaPrin, image = icone, command = #calculadora)
  393. #butCal.place(x=500, y=260)
  394.  
  395. credits = Label(janelaPrin, text="Desenvolvido por @danrleydaniel")
  396. credits.place(x=40, y=400)
  397. credits["bg"] = "white"
  398.  
  399.  
  400. janelaPrin.mainloop()
  401.  
  402. arqRef = open("ref.dat","wb")
  403. pickle.dump(refeicoes, arqRef)
  404. arqRef.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement