10/07/17 - 13:42 (Fase 1 concluída)
<syntaxhighlight lang="py">
from tkinter import * from functools import partial from tkinter import ttk
- ---------------------- janela *
janela = Tk() janela.geometry("500x500+400+0") janela.title("Think About Eat!") janela["bg"] = "#dec0f9"
#JANELA DE FAZER O LOGIN
- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
def tenho_rest(): login = Tk() login["bg"] = "#dec0f9" login.geometry("300x300+300+0") login.title("Autenticação")
usuario = Label(login, text = "Usuário: ", bg = "#dec0f9") usuario.pack(fill = BOTH) us = Entry(login) us.pack()
senha = Label(login, text = "Senha: ", bg = "#dec0f9") senha.pack() se = Entry(login, show = '*') se.pack()
#-------------Valida a senha def valido(): user = us.get() password = se.get()
arquivo = open('senhas.txt', 'r') texto = arquivo.readlines() arquivo.close()
k = 0 for linha in texto: lista = linha.split('*') if lista[0] == user: k = 1; if lista[1] == password: login.destroy() s = "" for i in lista[2]: if i != '\n': s += i meu_rest(s) else: errou = Label(login, text = "Ahh, não! Algo está errado!", bg = "#dec0f9") errou.pack() if k == 0: errou = Label(login, text = "Ahh, não! Algo está errado!", bg = "#dec0f9") errou.pack()
#---------------Botão confirmar finish = Button(login, text = "Pronto!", font = "Calibri 10 bold", bg = "#4f8c56", fg = "white", relief = "flat", command = valido) finish.pack() login.mainloop()
- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
#FRAME DO DONO DO RESTAURANTE
- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
def meu_rest(nome_rest): rest = Tk() rest["bg"] = "#dec0f9" rest.geometry("500x500+300+0") rest.title("Meu restaurante")
nome = Label(rest, text = nome_rest, font = ("Helvetica Neue 95 Black", 16), bg = "#dec0f9") nome.pack()
tabela = ttk.Treeview(rest, selectmode = 'browse', show = 'headings' , height = 7)
arquivo = open('dado.txt', 'r') texto = arquivo.readlines() arquivo.close()
g = -1 for linha in texto: lista = linha.split('*') if len(lista) and lista[0] == nome_rest: g+=1 if g != -1: g+=1 if g == 2: i = 0 while i < len(lista)-1: tabela.insert("", 'end', text = "L1", values = (lista[i], lista[i+1])) i+=2 elif g == 3: i = 0 while i < len(lista)-1: tabela.insert("", 'end', text = "L1", values = (lista[i], lista[i+1])) i+=2 elif g == 4: i = 0 while i < len(lista)-1: tabela.insert("", 'end', text = "L1", values = (lista[i], lista[i+1])) i+=2 elif g == 5: i = 0 while i < len(lista)-1: tabela.insert("", 'end', text = "L1", values = (lista[i], lista[i+1])) i+=2 g = -1 break
#------------------------ Tabela de produtos
tabela.pack() tabela["columns"] = ("1", "2") tabela['show'] = 'headings'
tabela.column("1", width=150, anchor='c') tabela.column("2", width=150, anchor='c')
tabela.heading("1", text="Nome") tabela.heading("2", text="Preço")
#-------------------------------------
#------------------------Função para deletar o restaurante def delete_rest():
j1 = Tk() j1.geometry("250x250+300+150") j1.title("Validação") tit = Label(j1, text="Digite sua senha:") tit.pack() sen = Entry(j1, show = '*') sen.pack()
#Valido a senha def valido(): senha = sen.get() arquivo = open('senhas.txt', 'r') texto = arquivo.readlines() arquivo.close() for linha in texto: lista = linha.split('*') s = "" for i in lista[2]: if i != '\n': s += i if len(lista) and s == nome_rest: if lista[1] == senha: deleta() else: errou = Label(j1, text = "Ahh, não! Algo está errado!") errou.pack()
def deleta(): #Deleto do arquivo de restaurantes arquivo = open('dado.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('dado.txt', 'w') k = 0 for linha in texto: lista = linha.split('*') if k == 4: k = 0 if lista[0] != nome and k < 4: arquivo.write(linha) else: k += 1
arquivo.close()
#Deleto do arquivo de logins arquivo = open('senhas.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('senhas.txt', 'w') for linha in texto: lista = linha.split('*') s = "" for i in lista[2]: if i != '\n': s += i if s != nome_rest: arquivo.writelines(linha) arquivo.close() j1.destroy() rest.destroy()
#-----------------Botão confirmar ok = Button(j1, compound = "left", bg = "#54d863", text = "Ok", font = "Calibri 11", relief = "flat", command = valido) ok.pack()
#-------------------------------------------------------
#------------------------Função para adicionar algo no cardápio
def add_card():
add = Tk()
add.geometry("250x250+300+150")
add.title("Adicionar produto")
nome = nome_rest tip = Label(add, text="Tipo do produto:") tip.pack() ex = Label(add, text="(entrada, principal, sobremesa ou bebida)", font = ("Calibri 11", 6)) ex.pack() t = Entry(add) t.pack() nom = Label(add, text="Nome:") nom.pack() n = Entry(add) n.pack() prec = Label(add, text="Preço:") prec.pack() ex1 = Label(add, text="Ex: R$2,00", font = ("Calibri 11", 6)) ex1.pack() p = Entry(add) p.pack()
# Adiciona def valide(): tipo = t.get() novo = n.get() preco = p.get()
arquivo = open('dado.txt', 'r') texto = arquivo.readlines() arquivo.close()
#--------------------- Verifico se já existe h = 0 g = -1 y = -1 b = 0 x = 0 for linha in texto: lista = linha.split('*') print(nome) print(lista[0]) if len(lista) and lista[0] == nome: print("OIIIIII") y += 1 if tipo == 'entrada': b = 1 elif tipo == 'principal': b = 2 elif tipo == 'sobremesa': b = 3 elif tipo == 'bebida': b = 4 else: break elif y != -1: y += 1 if b == y: for i in lista: if i == novo: x = 1 nao = Label(add, text = "Produto já existente.", font = ("Calibri 11", 8)) nao.pack() break
#----------------------- Se nao existir, crio if x == 0: arquivo = open('dado.txt', 'w') for linha in texto: lista = linha.split('*') if len(lista) and lista[0] == nome: g = 0 if tipo == 'entrada': h = 1 elif tipo == 'principal': h = 2 elif tipo == 'sobremesa': h = 3 elif tipo == 'bebida': h = 4 else: nao = Label(add, text = "Tipo de produto inválido.", font = ("Calibri 11", 8)) nao.pack() if g != -1 and h != 0: g+=1 if g == h: k = len(linha) linha += novo linha += '*' linha += preco linha += '*' arquivo.writelines(linha) arquivo.close() if h != 0: add.destroy() rest.destroy() meu_rest(nome_rest)
#-------------------Botão confirmar finish = Button(add, text = "Pronto!", compound = "left", bg = "#54d863", font = "Calibri 11", relief = "flat", command = valide) finish.place(x = 100, y = 300) finish.pack() add.mainloop()
#--------------------------------------------------
#----------------- Função para deletar algo do cardápio def del_card(): delete = Tk() delete.geometry("250x250+300+150") delete.title("Deletar produto")
tip = Label(delete, text="Tipo do produto:") tip.pack() ex = Label(delete, text="(entrada, principal, sobremesa ou bebida)", font = ("Calibri 11", 6)) ex.pack() t = Entry(delete) t.pack() nom = Label(delete, text="Nome:") nom.pack() n = Entry(delete) n.pack() t.pack() n.pack()
# Deleta def valide(): tipo = t.get() comida = n.get()
arquivo = open('dado.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('dado.txt', 'w')
h = 0 g = -2 c = 0 for linha in texto: lista = linha.split('*') if len(lista) and lista[0] == nome_rest: g = -1 if tipo == 'entrada': h = 1 elif tipo == 'principal': h = 2 elif tipo == 'sobremesa': h = 3 elif tipo == 'bebida': h = 4 else: nao = Label(delete, text = "Tipo de produto inválido.", font = ("Calibri 11", 8)) nao.pack() u = 0 lista2 = [] if g != -2 and h != 0: g+=1 if g == h: s = u = 1 v = 0 lista1 = linha.split('*') for i in lista1: if i == comida: v = 1 c = 1 elif v == 1: v = 0 else: if i != "\n": lista2.append(i+'*') lista2.append('\n') if u == 1: arquivo.writelines(lista2) else: arquivo.writelines(linha)
if c == 0 and h != 0: nao = Label(delete, text = "Esse produto não foi encontrado.", font = ("Calibri 11", 8)) nao.pack() nao1 = Label(delete, text = "Tente Novamente!", font = ("Calibri 11", 8)) nao1.pack() elif h != 0: arquivo.close() delete.destroy() rest.destroy() meu_rest(nome_rest)
#-------------Botão confirmar finish = Button(delete, text = "Pronto!", compound = "left", bg = "#54d863", font = "Calibri 11", relief = "flat", command = valide) finish.place(x = 100, y = 300) finish.pack() delete.mainloop()
#---------------------------------------------------------
#----------------------------------------------------------Função para atualizar produto
def att_card(): atualizar = Tk() atualizar.geometry("250x250+300+150") atualizar.title("Deletar produto")
tip = Label(atualizar, text="Tipo do produto:") tip.pack() ex = Label(atualizar, text="(entrada, principal, sobremesa ou bebida)", font = ("Calibri 11", 6)) ex.pack() t = Entry(atualizar) t.pack() nom = Label(atualizar, text="Nome:") nom.pack() n = Entry(atualizar) n.pack() newnom = Label(atualizar, text="Novo nome:") newnom.pack() new = Entry(atualizar) new.pack() newp = Label(atualizar, text="Novo preço:") newp.pack() ex1 = Label(atualizar, text="Ex: R$2,00", font = ("Calibri 11", 6)) ex1.pack() np = Entry(atualizar) np.pack()
# Atualiza def valide(): tipo = t.get() comida = n.get() novonome = new.get() novopreco = np.get()
arquivo = open('dado.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('dado.txt', 'w')
h = 0 g = -2 c = 0 for linha in texto: lista = linha.split('*') if len(lista) and lista[0] == nome_rest: g = -1 if tipo == 'entrada': h = 1 elif tipo == 'principal': h = 2 elif tipo == 'sobremesa': h = 3 elif tipo == 'bebida': h = 4 else: nao = Label(atualizar, text = "Tipo de produto inválido.", font = ("Calibri 11", 8)) nao.pack() u = 0 lista2 = [] if g != -2 and h != 0: g+=1 if g == h: s = u = 1 v = 0 lista1 = linha.split('*') for i in lista1: if i == comida: v = 1 c = 1 lista2.append(novonome+'*') elif v == 1: v = 0 lista2.append(novopreco+'*') else: if i != "\n": lista2.append(i+'*') lista2.append('\n') if u == 1: arquivo.writelines(lista2) else: arquivo.writelines(linha)
if c == 0 and h != 0: nao = Label(atualizar, text = "Esse produto não foi encontrado.", font = ("Calibri 11", 8)) nao.pack() nao1 = Label(atualizar, text = "Tente Novamente!", font = ("Calibri 11", 8)) nao1.pack() elif h != 0: arquivo.close() atualizar.destroy() rest.destroy() meu_rest(nome_rest)
#-------------Botão confirmar finish = Button(atualizar, text = "Pronto!", compound = "left", bg = "#54d863", font = "Calibri 11", relief = "flat", command = valide) finish.place(x = 100, y = 300) finish.pack() atualizar.mainloop()
#---------------------------------------------------------------------------------
#------------------- Botoes de adicionar, deletar e atualizar
b_add = Button(rest, compound = "left", bg = "#54d863", text = "Adicionar produto", font = "Calibri 11", relief = "flat", command = add_card)
b_add.pack()
b_del = Button(rest, compound = "left", bg = "#ff1616", text = "Deletar produto", font = "Calibri 11", relief = "flat", command=del_card)
b_del.pack()
b_att = Button(rest, compound = "left", bg = "#fcf811", text = "Atualizar produto", font = "Calibri 11", relief = "flat", command=att_card)
b_att.pack()
b_del_rest = Button(rest, compound = "left", bg = "#000000", fg = "white", text = "Deletar restaurante", font = "Calibri 11", relief = "flat", command=delete_rest)
b_del_rest.pack()
rest.mainloop()
#-------------------------------------------------------------------
- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
- -------------------------- cria o login e cadastra restaurante
def criar_rest(): janela_cria = Tk() janela_cria.geometry("500x650+350+0") janela_cria["bg"] = "#dec0f9" janela_cria.title("Cadastro") create = Frame(janela_cria) create["bg"] = "#dec0f9" dado_r = Label(create, text = "\n\nDados do restaurante ", bg = "#dec0f9", font = "Calibri 8", fg = "#515151") dado_r.pack()
rest1 = Label(create, text = "Nome: ", bg = "#dec0f9") rest1.pack() rest = Entry(create) rest.pack()
cnpj1 = Label(create, text = "CNPJ: ", bg = "#dec0f9") cnpj1.pack() cnpj = Entry(create) cnpj.pack()
tel1 = Label(create, text = "Telefone: ", bg = "#dec0f9") tel1.pack() tel = Entry(create) tel.pack()
end1 = Label(create, text = "Endereço: ", bg = "#dec0f9") end1.pack() end = Entry(create) end.pack()
info1 = Label(create, text = "Informações adicionais: ", bg = "#dec0f9") info1.pack() info = Entry(create) info.pack()
#Quais as "categorias" de comidas que posso achar no restaurante
check = Label(create, text = "Nesse restaurante posso encontrar... ", bg = "#dec0f9") check.pack()
x = IntVar() x1 = IntVar() x2 = IntVar() x3 = IntVar() x4 = IntVar() x5 = IntVar()
c1 = Checkbutton(create, text = "Comida japonesa", bg = "#dec0f9", onvalue = 1, offvalue = 0, variable = x) c1.pack() c2 = Checkbutton(create, text = "Pizza", bg = "#dec0f9", onvalue = 1, offvalue = 0, variable = x1) c2.pack() c3 = Checkbutton(create, text = "Sanduíches", bg = "#dec0f9", onvalue = 1, offvalue = 0, variable = x2) c3.pack() c4 = Checkbutton(create, text = "Caldos", bg = "#dec0f9", onvalue = 1, offvalue = 0, variable = x3) c4.pack() c5 = Checkbutton(create, text = "Fast food", bg = "#dec0f9", onvalue = 1, offvalue = 0, variable = x4) c5.pack() c6 = Checkbutton(create, text = "Cachorro-quente", bg = "#dec0f9", onvalue = 1, offvalue = 0, variable = x5) c6.pack()
vet = [x, x1, x2, x3, x4, x5]
dado_u = Label(create, text = "\n\nDados do usuário ", bg = "#dec0f9", font = "Calibri 8", fg = "#515151") dado_u.pack()
usuario1 = Label(create, text = "Nome do usuário: ", bg = "#dec0f9") usuario1.pack() us1 = Entry(create) us1.pack()
senha1 = Label(create, text = "Senha: ", bg = "#dec0f9") senha1.pack() se1 = Entry(create, show = '*') se1.pack()
nsenha1 = Label(create, text = "Redigite a senha: ", bg = "#dec0f9") nsenha1.pack() nse1 = Entry(create, show = '*') nse1.pack()
restricao = Label(create, text = "*Mínimo de 8 caracteres; diferencia maiúsculas de minúsculas\n", font = "Calibri 8", fg = "#515151", bg = "#dec0f9") restricao.pack() def valida() : user = us1.get() password = se1.get() npassword = nse1.get() if len(password) >= 8: if password == npassword: REST = rest.get() CNPJ = cnpj.get() TEL = tel.get() END = end.get() INFO = info.get()
arquivo = open("senhas.txt", 'r') texto = arquivo.readlines() arquivo.close()
flag = 0
for linha in texto: lista = linha.split('*') s = "" for i in lista[2]: if i != '\n': s += i
r = "" for i in lista[0]: if i != '\n': r += i if s == REST: flag = 1 elif r == user: flag = 2 if flag == 0: ac = Label(create, text = "Cadastro concluído!", bg = "#dec0f9") ac.pack() arquivo = open("dado.txt", 'a') arquivo.write(REST + '*' + CNPJ + '*' + TEL + '*' + END + '*' + INFO + '\n') arquivo.write("\n\n\n\n") arquivo.close()
arquivo = open("senhas.txt", 'a') arquivo.write(user + '*' + password + '*' + REST + '\n') arquivo.close()
arquivo = open("classifica.txt", 'r') lista = arquivo.readlines() arquivo.close()
arquivo = open("classifica.txt", 'w')
for i in range(0, 6): a = vet[i].get() s = "" for j in range(0, len(lista[i])-1): s += lista[i][j] if a == 1: V = s.split('*') flag = False for k in V: if k == REST: flag = True break if flag == False: arquivo.write(s + REST + "*\n") else: arquivo.write(s + '\n') arquivo.close() elif flag == 1: ac = Label(create, text = "Restaurante já existente! Tente novamente!", bg = "#dec0f9") ac.pack() else: ac = Label(create, text = "Usuário já existente! Tente novamente!", bg = "#dec0f9") ac.pack() else: errou = Label(create, text = "Ahh, não! Algo está errado!", bg = "#dec0f9") errou.pack() else: errou = Label(create, text = "Número de caracteres insuficiente. Tente novamente!", bg = "#dec0f9") errou.pack() finish = Button(create, text = "Pronto", font = "Calibri 10 bold", bg = "#4f8c56", fg = "white", relief = "flat", command = valida) finish.pack() create.pack() janela_cria.mainloop()
- --------------------------- tela categorias - opções de comidas para o cliente
s = PhotoImage(file = "/root/Larissa/ThinkAboutEat/sushi.gif") sushi = s.subsample(2, 2) p = PhotoImage(file = "/root/Larissa/ThinkAboutEat/pizza.gif") pz = p.subsample(2, 2) san = PhotoImage(file = "/root/Larissa/ThinkAboutEat/sanduiche.gif") sanduba = san.subsample(2, 2) c = PhotoImage(file = "/root/Larissa/ThinkAboutEat/sopa.gif") caldo = c.subsample(2, 2) f = PhotoImage(file = "/root/Larissa/ThinkAboutEat/fastfood.gif") ff = f.subsample(2, 2) h = PhotoImage(file = "/root/Larissa/ThinkAboutEat/hotdog.gif") hot = h.subsample(2, 2)
- ---------------------------- mostra a lista de restaurantes que servem _______________ (a string que eu passar na função, ex: pizza, comida japonesa)
def abre_jap(): abre_food("Comida japonesa", 0) def abre_pi(): abre_food("Pizza", 1) def abre_san(): abre_food("Sanduíches", 2) def abre_cal(): abre_food("Caldos", 3) def abre_fast(): abre_food("Fast food", 4) def abre_dog(): abre_food("Cachorro-quente", 5)
def abre_food(string, pos): food = Tk() food.geometry("400x400+350+0") food["bg"] = "#dec0f9" food.title(string) l = Listbox(food) l["bg"] = "#e8d1fc" l["height"] = 25 l["width"] = 40
arquivo = open("classifica.txt", 'r') vet = arquivo.readlines() aux = vet[pos].split('*')
for i in aux: if i != string and i != '\n': l.insert(END, i)
l.pack() food.mainloop()
- ----------------------------- cria os botões com as categorias disponíveis para o cliente
def categoria(): tela_c = Frame(janela) tela_c["bg"] = "#dec0f9" home.destroy() comida_japonesa= Button(tela_c, text = "COMIDA JAPONESA", image = sushi, compound = "left", font = "Calibri 15 bold", bg = "#395061", fg = "white", width = 250, command = abre_jap) comida_japonesa.pack() pizza = Button(tela_c, text = "PIZZA", image = pz, compound = "right", font = "Calibri 15 bold", bg = "#2cb69d", fg = "white", width = 250, command = abre_pi) pizza.pack() sanduiche = Button(tela_c, text = "SANDUÍCHES", image = sanduba, compound = "left", font = "Calibri 15 bold", bg = "#6cbbe6", fg = "white", width = 250, command = abre_san) sanduiche.pack() caldos = Button(tela_c, text = "CALDOS", image = caldo, compound = "right", font = "Calibri 15 bold", bg = "#fed87a", fg = "white", width = 250, command = abre_cal) caldos.pack() fastfood = Button(tela_c, text = "FAST FOOD", image = ff, compound = "left", font = "Calibri 15 bold", bg = "#2a4350", fg = "white", width = 250, command = abre_fast) fastfood.pack() hotdog = Button(tela_c, text = "CACHORRO-QUENTE", image = hot, compound = "right", font = "Calibri 15 bold", bg = "#23a487", fg = "white", width = 250, command = abre_dog) hotdog.pack() tela_c.pack()
- --------------------------- home (janela inicial/principal)
home = Frame(janela) home["bg"] = "#dec0f9" c = PhotoImage(file = "/root/Larissa/ThinkAboutEat/pedido.gif") cestinha = c.subsample(3, 3) ch = PhotoImage(file = "/root/Larissa/ThinkAboutEat/tenho.gif") chef = ch.subsample(3, 3) mais = PhotoImage(file = "/root/Larissa/ThinkAboutEat/add1.gif") novo_rest = Button(home, image = mais, compound = "left", text = "Adicionar restaurante", bg = "white", font = "Calibri 11", height = 18, width = 180, relief = "flat", command = criar_rest) pedido = Button(home, image = cestinha, compound = "left", text = "Fazer pedido", font = "Calibri 11", height = 18, width = 180, bg = "white", relief = "flat", command = categoria) tenho = Button(home, image = chef, compound = "left", bg = "white", text = "Já tenho um restaurante", height = 18, width = 180, font = "Calibri 11", relief = "flat", command = tenho_rest) pedido.grid(row = 0, column = 0) novo_rest.grid(row = 1, column = 0) tenho.grid(row = 2, column = 0) home.pack() janela.mainloop() </syntaxhighlight>
26/06/2017 - 22:10 - Fase 1 concluída
<syntaxhighlight lang="py">
from tkinter import * from functools import partial from tkinter import ttk
#JANELA
- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
janela = Tk() janela.geometry("400x400+200+200") janela.title("Think About Eat!") janela["bg"] = "#eeddff"
- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
#FRAME DE FAZER O LOGIN
- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
def tenho_rest(): home.destroy() login = Frame() login["bg"] = "#eeddff"
usuario = Label(login, text = "Usuário: ", bg = "#eeddff") usuario.pack(fill = BOTH) us = Entry(login) us.pack()
senha = Label(login, text = "Senha: ", bg = "#eeddff") senha.pack() se = Entry(login, show = '*') se.pack()
#-------------Valida a senha def valido(): user = us.get() password = se.get()
arquivo = open('senhas.txt', 'r') texto = arquivo.readlines() arquivo.close()
k = 0 for linha in texto: lista = linha.split() if lista[0] == user: k = 1; if lista[1] == password: login.destroy() us.destroy() se.destroy() meu_rest(lista[2]) else: errou = Label(login, text = "Ahh, não! Algo está errado!", bg = "#d1fce1") errou.pack() if k == 0: errou = Label(login, text = "Ahh, não! Algo está errado!", bg = "#d1fce1") errou.pack()
#---------------Botão confirmar finish = Button(login, text = "Pronto!", font = "Calibri 10 bold", bg = "#4f8c56", fg = "white", relief = "flat", command = valido) finish.pack() login.pack()
- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
#FRAME DO DONO DO RESTAURANTE
- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
def meu_rest(nome_rest): rest = Frame() rest["bg"] = "#eeddff"
nome = Label(rest, text = nome_rest, font = ("Helvetica Neue 95 Black", 16), bg = "#eeddff") nome.pack()
tabela = ttk.Treeview(rest, selectmode = 'browse', show = 'headings' , height = 7)
arquivo = open('dado.txt', 'r') texto = arquivo.readlines() arquivo.close()
g = -1 for linha in texto: lista = linha.split() if len(lista) and lista[0] == nome_rest: g+=1 if g != -1: g+=1 if g == 2: i = 0 lista = linha.split() while i < len(lista): tabela.insert("", 'end', text = "L1", values = (lista[i], lista[i+1])) i+=2 elif g == 3: i = 0 lista = linha.split() while i < len(lista): tabela.insert("", 'end', text = "L1", values = (lista[i], lista[i+1])) i+=2 elif g == 4: i = 0 lista = linha.split() while i < len(lista): tabela.insert("", 'end', text = "L1", values = (lista[i], lista[i+1])) i+=2 elif g == 5: i = 0 lista = linha.split() while i < len(lista): tabela.insert("", 'end', text = "L1", values = (lista[i], lista[i+1])) i+=2 g = -1 break
#------------------------ Tabela de produtos
tabela.pack() tabela["columns"] = ("1", "2") tabela['show'] = 'headings'
tabela.column("1", width=150, anchor='c') tabela.column("2", width=150, anchor='c')
tabela.heading("1", text="Nome") tabela.heading("2", text="Preço")
#-------------------------------------
#------------------------Função para deletar o restaurante def delete_rest():
j1 = Tk() j1.geometry("250x250+300+150") j1.title("Validação") tit = Label(j1, text="Digite sua senha:") tit.pack() sen = Entry(j1, show = '*') sen.pack()
#Valido a senha def valido(): senha = sen.get() arquivo = open('senhas.txt', 'r') texto = arquivo.readlines() arquivo.close()
for linha in texto: lista = linha.split() if len(lista) and lista[2] == nome_rest: if lista[1] == senha: deleta() else: errou = Label(j1, text = "Ahh, não! Algo está errado!") errou.pack()
def deleta(): #Deleto do arquivo de restaurantes arquivo = open('dado.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('dado.txt', 'w') k = -2; for linha in texto: lista = linha.split() if len(lista) and lista[0] == nome_rest: k = -1 if k != -2: k+=1 if k == -1: arquivo.writelines(linha) if k == 4: k = -1 arquivo.close()
#Deleto do arquivo de logins arquivo = open('senhas.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('senhas.txt', 'w') k = -2; for linha in texto: lista = linha.split() if lista[2] != nome_rest: arquivo.writelines(linha) arquivo.close() j1.destroy() janela.destroy()
#-----------------Botão confirmar ok = Button(j1, compound = "left", bg = "#54d863", text = "Ok", font = "Calibri 11", relief = "flat", command = valido) ok.pack()
#-------------------------------------------------------
#------------------------Função para adicionar algo no cardápio
def add_card():
add = Tk()
add.geometry("250x250+300+150")
add.title("Adicionar produto")
nome = nome_rest tip = Label(add, text="Tipo do produto:") tip.pack() ex = Label(add, text="(entrada, principal, sobremesa ou bebida)", font = ("Calibri 11", 6)) ex.pack() t = Entry(add) t.pack() nom = Label(add, text="Nome:") nom.pack() n = Entry(add) n.pack() prec = Label(add, text="Preço:") prec.pack() ex1 = Label(add, text="Ex: R$2,00", font = ("Calibri 11", 6)) ex1.pack() p = Entry(add) p.pack()
# Adiciona def valide(): tipo = t.get() novo = n.get() preco = p.get()
arquivo = open('dado.txt', 'r') texto = arquivo.readlines() arquivo.close()
#--------------------- Verifico se já existe h = 0 g = -1 y = -1 b = 0 x = 0 for linha in texto: lista = linha.split() if len(lista) and lista[0] == nome: y += 1 if tipo == 'entrada': b = 1 elif tipo == 'principal': b = 2 elif tipo == 'sobremesa': b = 3 elif tipo == 'bebida': b = 4 else: break elif y != -1: y += 1 if b == y: for i in lista: if i == novo: x = 1 nao = Label(add, text = "Produto já existente.", font = ("Calibri 11", 8)) nao.pack() break
#----------------------- Se nao existir, crio if x == 0: arquivo = open('dado.txt', 'w') for linha in texto: lista = linha.split() if len(lista) and lista[0] == nome: g = 0 if tipo == 'entrada': h = 1 elif tipo == 'principal': h = 2 elif tipo == 'sobremesa': h = 3 elif tipo == 'bebida': h = 4 else: nao = Label(add, text = "Tipo de produto inválido.", font = ("Calibri 11", 8)) nao.pack() if g != -1 and h != 0: g+=1 if g == h: k = len(linha) linha += novo linha += ' ' linha += preco linha += ' ' arquivo.writelines(linha) arquivo.close() if h != 0: add.destroy() rest.destroy() meu_rest(nome_rest)
#-------------------Botão confirmar finish = Button(add, text = "Pronto!", compound = "left", bg = "#54d863", font = "Calibri 11", relief = "flat", command = valide) finish.place(x = 100, y = 300) finish.pack() add.mainloop()
#--------------------------------------------------
#----------------- Função para deletar algo do cardápio def del_card(): delete = Tk() delete.geometry("250x250+300+150") delete.title("Deletar produto")
tip = Label(delete, text="Tipo do produto:") tip.pack() ex = Label(delete, text="(entrada, principal, sobremesa ou bebida)", font = ("Calibri 11", 6)) ex.pack() t = Entry(delete) t.pack() nom = Label(delete, text="Nome:") nom.pack() n = Entry(delete) n.pack() t.pack() n.pack()
# Deleta def valide(): tipo = t.get() comida = n.get()
arquivo = open('dado.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('dado.txt', 'w')
h = 0 g = -2 c = 0 for linha in texto: lista = linha.split() if len(lista) and lista[0] == nome_rest: g = -1 if tipo == 'entrada': h = 1 elif tipo == 'principal': h = 2 elif tipo == 'sobremesa': h = 3 elif tipo == 'bebida': h = 4 else: nao = Label(delete, text = "Tipo de produto inválido.", font = ("Calibri 11", 8)) nao.pack() u = 0 lista2 = [] if g != -2 and h != 0: g+=1 if g == h: s = u = 1 v = 0 lista1 = linha.split() for i in lista1: if i == comida: v = 1 c = 1 elif v == 1: v = 0 else: lista2.append(i+' ') lista2.append('\n') if u == 1: arquivo.writelines(lista2) else: arquivo.writelines(linha)
if c == 0 and h != 0: nao = Label(delete, text = "Esse produto não foi encontrado.", font = ("Calibri 11", 8)) nao.pack() nao1 = Label(delete, text = "Tente Novamente!", font = ("Calibri 11", 8)) nao1.pack() elif h != 0: arquivo.close() delete.destroy() rest.destroy() meu_rest(nome_rest)
#-------------Botão confirmar finish = Button(delete, text = "Pronto!", compound = "left", bg = "#54d863", font = "Calibri 11", relief = "flat", command = valide) finish.place(x = 100, y = 300) finish.pack() delete.mainloop()
#---------------------------------------------------------
#----------------------------------------------------------Função para atualizar produto
def att_card(): atualizar = Tk() atualizar.geometry("250x250+300+150") atualizar.title("Deletar produto")
tip = Label(atualizar, text="Tipo do produto:") tip.pack() ex = Label(atualizar, text="(entrada, principal, sobremesa ou bebida)", font = ("Calibri 11", 6)) ex.pack() t = Entry(atualizar) t.pack() nom = Label(atualizar, text="Nome:") nom.pack() n = Entry(atualizar) n.pack() newnom = Label(atualizar, text="Novo nome:") newnom.pack() new = Entry(atualizar) new.pack() newp = Label(atualizar, text="Novo preço:") newp.pack() ex1 = Label(atualizar, text="Ex: R$2,00", font = ("Calibri 11", 6)) ex1.pack() np = Entry(atualizar) np.pack()
# Atualiza def valide(): tipo = t.get() comida = n.get() novonome = new.get() novopreco = np.get()
arquivo = open('dado.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('dado.txt', 'w')
h = 0 g = -2 c = 0 for linha in texto: lista = linha.split() if len(lista) and lista[0] == nome_rest: g = -1 if tipo == 'entrada': h = 1 elif tipo == 'principal': h = 2 elif tipo == 'sobremesa': h = 3 elif tipo == 'bebida': h = 4 else: nao = Label(atualizar, text = "Tipo de produto inválido.", font = ("Calibri 11", 8)) nao.pack() u = 0 lista2 = [] if g != -2 and h != 0: g+=1 if g == h: s = u = 1 v = 0 lista1 = linha.split() for i in lista1: if i == comida: v = 1 c = 1 lista2.append(novonome+' ') elif v == 1: v = 0 lista2.append(novopreco+' ') else: lista2.append(i+' ') lista2.append('\n') if u == 1: arquivo.writelines(lista2) else: arquivo.writelines(linha)
if c == 0 and h != 0: nao = Label(atualizar, text = "Esse produto não foi encontrado.", font = ("Calibri 11", 8)) nao.pack() nao1 = Label(atualizar, text = "Tente Novamente!", font = ("Calibri 11", 8)) nao1.pack() elif h != 0: arquivo.close() atualizar.destroy() rest.destroy() meu_rest(nome_rest)
#-------------Botão confirmar finish = Button(atualizar, text = "Pronto!", compound = "left", bg = "#54d863", font = "Calibri 11", relief = "flat", command = valide) finish.place(x = 100, y = 300) finish.pack() atualizar.mainloop()
#---------------------------------------------------------------------------------
#------------------- Botoes de adicionar e deletar
b_add = Button(rest, compound = "left", bg = "#54d863", text = "Adicionar produto", font = "Calibri 11", relief = "flat", command = add_card)
b_add.pack()
b_del = Button(rest, compound = "left", bg = "#ff1616", text = "Deletar produto", font = "Calibri 11", relief = "flat", command=del_card)
b_del.pack()
b_att = Button(rest, compound = "left", bg = "#fcf811", text = "Atualizar produto", font = "Calibri 11", relief = "flat", command=att_card)
b_att.pack()
b_del_rest = Button(rest, compound = "left", bg = "#000000", fg = "white", text = "Deletar restaurante", font = "Calibri 11", relief = "flat", command=delete_rest)
b_del_rest.pack()
rest.pack()
#-------------------------------------------------------------------
- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
#FRAME PRINCIPAL
- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
home = Frame(janela) tenho = Button(home, compound = "left", bg = "white", text = "Já tenho um restaurante", font = "Calibri 11", relief = "flat", command = tenho_rest) tenho.pack() home.pack() janela.mainloop() </syntaxhighlight>
26/06/2017 - 13:55
<syntaxhighlight lang="py">
from tkinter import * from functools import partial from tkinter import ttk
#JANELA
- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
janela = Tk() janela.geometry("300x300+200+200") janela.title("Think About Eat!") janela["bg"] = "#eeddff"
- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
#FRAME DE FAZER O LOGIN
- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
def tenho_rest(): home.destroy() login = Frame() login["bg"] = "#eeddff"
usuario = Label(login, text = "Usuário: ", bg = "#eeddff") usuario.pack(fill = BOTH) us = Entry(login) us.pack()
senha = Label(login, text = "Senha: ", bg = "#eeddff") senha.pack() se = Entry(login, show = '*') se.pack()
#-------------Valida a senha def valido(): user = us.get() password = se.get()
arquivo = open('senhas.txt', 'r') texto = arquivo.readlines() arquivo.close()
k = 0 for linha in texto: lista = linha.split() if lista[0] == user: k = 1; if lista[1] == password: login.destroy() us.destroy() se.destroy() meu_rest(lista[2]) else: errou = Label(login, text = "Ahh, não! Algo está errado!", bg = "#d1fce1") errou.pack() if k == 0: errou = Label(login, text = "Ahh, não! Algo está errado!", bg = "#d1fce1") errou.pack()
finish = Button(login, text = "Pronto!", font = "Calibri 10 bold", bg = "#4f8c56", fg = "white", relief = "flat", command = valido) finish.pack() login.pack()
- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
#FRAME DO DONO DO RESTAURANTE
- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
def meu_rest(nome_rest): rest = Frame() rest["bg"] = "#eeddff"
nome = Label(rest, text = nome_rest, font = ("Helvetica Neue 95 Black", 16), bg = "#eeddff") nome.pack()
tabela = ttk.Treeview(rest, selectmode = 'browse', show = 'headings' , height = 7)
arquivo = open('dado.txt', 'r') texto = arquivo.readlines() arquivo.close()
g = -1 for linha in texto: lista = linha.split() if len(lista) and lista[0] == nome_rest: g+=1 if g != -1: g+=1 if g == 2: i = 0 lista = linha.split() while i < len(lista): tabela.insert("", 'end', text = "L1", values = (lista[i], lista[i+1])) i+=2 elif g == 3: i = 0 lista = linha.split() while i < len(lista): tabela.insert("", 'end', text = "L1", values = (lista[i], lista[i+1])) i+=2 elif g == 4: i = 0 lista = linha.split() while i < len(lista): tabela.insert("", 'end', text = "L1", values = (lista[i], lista[i+1])) i+=2 elif g == 5: i = 0 lista = linha.split() while i < len(lista): tabela.insert("", 'end', text = "L1", values = (lista[i], lista[i+1])) i+=2 g = -1 break
#------------------------ Tabela de produtos
tabela.pack() tabela["columns"] = ("1", "2") tabela['show'] = 'headings'
tabela.column("1", width=150, anchor='c') tabela.column("2", width=150, anchor='c')
tabela.heading("1", text="Nome") tabela.heading("2", text="Preço")
#-------------------------------------
#------------------------Função para deletar o restaurante def delete_rest():
j1 = Tk() j1.geometry("250x250+300+150") j1.title("Validação") tit = Label(j1, text="Digite sua senha:") tit.pack() sen = Entry(j1, show = '*') sen.pack()
#Valido a senha def valido(): senha = sen.get() arquivo = open('senhas.txt', 'r') texto = arquivo.readlines() arquivo.close()
for linha in texto: lista = linha.split() if len(lista) and lista[2] == nome_rest: if lista[1] == senha: deleta() else: errou = Label(j1, text = "Ahh, não! Algo está errado!") errou.pack()
def deleta(): #Deleto do arquivo de restaurantes arquivo = open('dado.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('dado.txt', 'w') k = -2; for linha in texto: lista = linha.split() if len(lista) and lista[0] == nome_rest: k = -1 if k != -2: k+=1 if k == -1: arquivo.writelines(linha) if k == 4: k = -1 arquivo.close()
#Deleto do arquivo de logins arquivo = open('senhas.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('senhas.txt', 'w') k = -2; for linha in texto: lista = linha.split() if lista[2] != nome_rest: arquivo.writelines(linha) arquivo.close() j1.destroy() janela.destroy()
ok = Button(j1, compound = "left", bg = "#54d863", text = "Ok", font = "Calibri 11", relief = "flat", command = valido) ok.pack()
#-------------------------------------------------------
#------------------------Função para adicionar algo no cardápio
def add_card():
add = Tk()
add.geometry("250x250+300+150")
add.title("Adicionar produto")
nome = nome_rest tip = Label(add, text="Tipo do produto:") tip.pack() ex = Label(add, text="(entrada, principal, sobremesa ou bebida)", font = ("Calibri 11", 6)) ex.pack() t = Entry(add) t.pack() nom = Label(add, text="Nome:") nom.pack() n = Entry(add) n.pack() prec = Label(add, text="Preço:") prec.pack() ex1 = Label(add, text="Ex: R$2,00", font = ("Calibri 11", 6)) ex1.pack() p = Entry(add) p.pack()
# Adiciona def valide(): tipo = t.get() novo = n.get() preco = p.get()
arquivo = open('dado.txt', 'r') texto = arquivo.readlines() arquivo.close()
#--------------------- Verifico se já existe h = 0 g = -1 y = -1 b = 0 x = 0 for linha in texto: lista = linha.split() if len(lista) and lista[0] == nome: y += 1 if tipo == 'entrada': b = 1 elif tipo == 'principal': b = 2 elif tipo == 'sobremesa': b = 3 elif tipo == 'bebida': b = 4 else: break elif y != -1: y += 1 if b == y: for i in lista: if i == novo: x = 1 nao = Label(add, text = "Produto já existente.", font = ("Calibri 11", 8)) nao.pack() break
#----------------------- Se nao existir, crio if x == 0: arquivo = open('dado.txt', 'w') for linha in texto: lista = linha.split() if len(lista) and lista[0] == nome: g = 0 if tipo == 'entrada': h = 1 elif tipo == 'principal': h = 2 elif tipo == 'sobremesa': h = 3 elif tipo == 'bebida': h = 4 else: nao = Label(add, text = "Tipo de produto inválido.", font = ("Calibri 11", 8)) nao.pack() if g != -1 and h != 0: g+=1 if g == h: k = len(linha) linha += novo linha += ' ' linha += preco linha += ' ' arquivo.writelines(linha) arquivo.close() if h != 0: add.destroy() rest.destroy() meu_rest(nome_rest)
finish = Button(add, text = "Pronto!", compound = "left", bg = "#54d863", font = "Calibri 11", relief = "flat", command = valide) finish.place(x = 100, y = 300) finish.pack() add.mainloop()
#--------------------------------------------------
#----------------- Função para deletar algo do cardápio def del_card(): delete = Tk() delete.geometry("250x250+300+150") delete.title("Deletar produto")
tip = Label(delete, text="Tipo do produto:") tip.pack() ex = Label(delete, text="(entrada, principal, sobremesa ou bebida)", font = ("Calibri 11", 6)) ex.pack() t = Entry(delete) t.pack() nom = Label(delete, text="Nome:") nom.pack() n = Entry(delete) n.pack() t.pack() n.pack()
# Deleta def valide(): tipo = t.get() comida = n.get()
arquivo = open('dado.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('dado.txt', 'w')
h = 0 g = -2 c = 0 for linha in texto: lista = linha.split() if len(lista) and lista[0] == nome_rest: g = -1 if tipo == 'entrada': h = 1 elif tipo == 'principal': h = 2 elif tipo == 'sobremesa': h = 3 elif tipo == 'bebida': h = 4 else: nao = Label(delete, text = "Tipo de produto inválido.", font = ("Calibri 11", 8)) nao.pack() u = 0 lista2 = [] if g != -2 and h != 0: g+=1 if g == h: s = u = 1 v = 0 lista1 = linha.split() for i in lista1: if i == comida: v = 1 c = 1 elif v == 1: v = 0 else: lista2.append(i+' ') lista2.append('\n') if u == 1: arquivo.writelines(lista2) else: arquivo.writelines(linha)
if c == 0 and h != 0: nao = Label(delete, text = "Esse produto não foi encontrado.", font = ("Calibri 11", 8)) nao.pack() nao1 = Label(delete, text = "Tente Novamente!", font = ("Calibri 11", 8)) nao1.pack() elif h != 0: arquivo.close() delete.destroy() rest.destroy() meu_rest(nome_rest)
finish = Button(delete, text = "Pronto!", compound = "left", bg = "#54d863", font = "Calibri 11", relief = "flat", command = valide) finish.place(x = 100, y = 300) finish.pack() delete.mainloop()
#---------------------------------------------------------
#------------------- Botoes de adicionar e deletar b_add = Button(rest, compound = "left", bg = "#54d863", text = "Adicionar produto", font = "Calibri 11", relief = "flat", command = add_card) b_add.pack() b_del = Button(rest, compound = "left", bg = "#ff1616", text = "Deletar produto", font = "Calibri 11", relief = "flat", command=del_card) b_del.pack() b_del_rest = Button(rest, compound = "left", bg = "#000000", fg = "white", text = "Deletar restaurante", font = "Calibri 11", relief = "flat", command=delete_rest) b_del_rest.pack() rest.pack() #-------------------------------------------------------------------
- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
#FRAME PRINCIPAL
- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
home = Frame(janela) tenho = Button(home, compound = "left", bg = "white", text = "Já tenho um restaurante", font = "Calibri 11", relief = "flat", command = tenho_rest) tenho.pack() home.pack() janela.mainloop() </syntaxhighlight>
19/06/2017 - 15:16
<syntaxhighlight lang="py">
from tkinter import * from functools import partial
- ---------------------- JANELA *
janela = Tk() janela.geometry("300x300+200+200") janela.title("Think About Eat!")
- janela["bg"] = "#d1fce"
- --------------------------- fazer login *
def tenho_rest(): home.destroy() login = Frame() usuario = Label(login, text = "Usuário: ") us = Entry() us.pack() senha = Label(login, text = "Senha: ") se = Entry(show = '*') se.pack() def valido(): user = us.get() password = se.get() arquivo = open('senhas.txt', 'r') texto = arquivo.readlines() arquivo.close() for linha in texto: lista = linha.split() if lista[0] == user: if lista[1] == password: login.destroy() us.destroy() se.destroy() meu_rest(lista[2]) else: errou = Label(login, text = "Ahh, não! Algo está errado!", bg = "#d1fce1") errou.pack() else: errou = Label(login, text = "Ahh, não! Algo está errado!", bg = "#d1fce1") errou.pack() finish = Button(login, text = "Pronto!", bg = "white", relief = "flat", command = valido) finish.pack() login.pack()
- ---------------------- Tenho Restaurante *
def meu_rest(nome_rest): rest = Frame() rest["bg"] = "#d1fce1" nome = Label(rest, text = nome_rest, bg = "#d1fce1") nome.pack() listbox = Listbox(rest, selectmode=EXTENDED) listbox.pack() arquivo = open('dados.txt', 'r') texto = arquivo.readlines() arquivo.close() g = -1 for linha in texto: lista = linha.split() if lista[0] == nome_rest: g+=1 if g != -1: g+=1 if g == 2: listbox.insert(END, "ENTRADAS") listbox.insert(END, ) i = 0 lista = linha.split() while i < len(lista): listbox.insert(END, lista[i]+" "+lista[i+1])#*lista[i:i+2]) i+=2 elif g == 3: listbox.insert(END, ) listbox.insert(END, "PRATOS PRINCIPAIS") listbox.insert(END, ) i = 0 lista = linha.split() while i < len(lista): listbox.insert(END, lista[i]+" "+lista[i+1])#*lista[i:i+2]) i+=2 elif g == 4: listbox.insert(END, ) listbox.insert(END, "SOBREMESAS") listbox.insert(END, ) i = 0 lista = linha.split() while i < len(lista): listbox.insert(END, lista[i]+" "+lista[i+1])#*lista[i:i+2]) i+=2 elif g == 5: listbox.insert(END, ) listbox.insert(END, "BEBIDAS") listbox.insert(END, ) i = 0 lista = linha.split() while i < len(lista): listbox.insert(END, lista[i]+" "+lista[i+1])#*lista[i:i+2]) i+=2 g = -1 break # Função para adicionar algo no cardápio def add_card(): add = Tk() add.geometry("250x250+300+150") add.title("Adicionar cardápio") nome = nome_rest t = Entry(add) n = Entry(add) p = Entry(add) t.pack() n.pack() p.pack() # Adiciona def valide(): tipo = t.get() novo = n.get() preco = p.get() arquivo = open('dados.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('dados.txt', 'w') h = 0 g = -1 for linha in texto: lista = linha.split() if lista[0] == nome: g = 0 if tipo == 'entrada': h = 1 elif tipo == 'principal': h = 2 elif tipo == 'sobremesa': h = 3 else: h = 4 if g != -1: g+=1 if g == h: k = len(linha) linha += novo linha += ' ' linha += preco linha += ' ' arquivo.writelines(linha) arquivo.close() add.destroy() rest.destroy() meu_rest(nome_rest) finish = Button(add, text = "Pronto!", bg = "white", relief = "flat", command = valide) finish.place(x = 100, y = 300) finish.pack() add.mainloop()
b_add = Button(rest, compound = "left", bg = "white", text = "Adicionar cardápio", font = "Calibri 11", relief = "flat", command = add_card) b_add.pack() b_del = Button(rest, compound = "left", bg = "white", text = "Deletar cardápio", font = "Calibri 11", relief = "flat", command=del_card) b_del.pack() rest.pack()
- ------------------- home
home = Frame(janela)
- home["bg"] = "#d1fce1"
tenho = Button(home, compound = "left", bg = "white", text = "Já tenho um restaurante", font = "Calibri 11", relief = "flat", command = tenho_rest) tenho.pack() home.pack() janela.mainloop() </syntaxhighlight>
17/06/2017 - 22:42
<syntaxhighlight lang="py">
from tkinter import *
- --------------------------------------- Deleta o restaurante
def delete_rest(): nome = input() arquivo = open('dados.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('dados.txt', 'w') k = -2; for linha in texto: lista = linha.split() if lista[0] == nome: k = -1 if k != -2: k+=1 if k == -1: arquivo.writelines(linha) if k == 4: k = -1 arquivo.close()
- --------------------------------------- Adicionar algo ao cardápio
def add_card(): nome = input() tipo = input() novo = input() preco = input() arquivo = open('dados.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('dados.txt', 'w') h = 0 g = -1 for linha in texto: lista = linha.split() if lista[0] == nome: g = 0 if tipo == 'entrada': h = 1 elif tipo == 'principal': h = 2 elif tipo == 'sobremesa': h = 3 else: h = 4 if g != -1: g+=1 if g == h: k = len(linha) linha += novo linha += ' ' linha += preco linha += ' ' arquivo.writelines(linha) arquivo.close()
- --------------------------------------- Deleta algo do cardápio
def del_card(): rest = input() tipo = input() comida = input() arquivo = open('dados.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('dados.txt', 'w') h = 0 g = -2 for linha in texto: lista = linha.split() if lista[0] == rest: g = -1 if tipo == 'entrada': h = 1 elif tipo == 'principal': h = 2 elif tipo == 'sobremesa': h = 3 else: h = 4 v = 0 u = 0 lista2 = [] if g != -2: g+=1 if g == h: s = u = 1 lista1 = linha.split() for i in lista1: if i == comida: v = 1 elif v == 1: v = 0 else: lista2.append(i+' ') lista2.append('\n') if u == 1: arquivo.writelines(lista2) else: arquivo.writelines(linha) arquivo.close()
- --------------------------------------------- Le as informações pra criar o restaurante
def read(): lista = [] nome = input() lista.append(nome+' ') cnpj = input() lista.append(cnpj+' ') endereco = input() lista.append(endereco+' ') telefone = input() lista.append(telefone+'\n') return lista
- ----------------------------------------------- Criar restaurante
def criar_rest(): restaurante = read() arquivo = open('dados.txt', 'a') arquivo.writelines(restaurante) entrada = input() precoe = input() principal = input() precop = input() sobremesa = input() precos = input() bebida = input() precob = input() en = [] en.append(entrada+' ') en.append(precoe+'\n') pri = [] pri.append(principal+' ') pri.append(precop+'\n') sob = [] sob.append(sobremesa+' ') sob.append(precos+'\n') be = [] be.append(bebida+' ') be.append(precob+'\n') arquivo.writelines(en) arquivo.writelines(pri) arquivo.writelines(sob) arquivo.writelines(be) arquivo.close()
- ---------------------- Procurar Restaurante
def procurar_rest(): nome = input() arquivo = open('dados.txt', 'r') texto = arquivo.readlines() j = 0 for i in texto: lista = i.split() if lista[0] == nome: print(lista) j = 1 break if j == 0: print('Restaurante nao encontrado') arquivo.close()
- criar_rest()
- print("Procure: ")
- procurar_rest()
- print("Adicione cardapio: ")
- add_card()
- print("Delete cardapio: ")
- del_card()
- print("Delete rest: ")
- delete_rest()
class restaurante(): def __init__(self): nome = "-" cnpj = "-" telefone = "-" endereco = "-"
- ---------------------- JANELA *
janela = Tk() janela.geometry("500x500+200+200") janela.title("Think About Eat!") janela["bg"] = "#eeddff"
- --------------------------- fazer login *
login = Frame(janela) usuario = Label(login, text = "Usuário: ") us = Entry() senha = Label(login, text = "Senha: ") se = Entry(show = '*') user = us.get() password = se.get()
- -------------------------- criar login * (colocar função de criar cardápio no botão "pronto")
def criar_rest(): #temp = Frame() #temp = home home.destroy() create = Frame(janela) create["bg"] = "#eeddff" janela.title("Cadastro") dado_r = Label(create, text = "\n\nDados do restaurante ", bg = "#eeddff", font = "Calibri 8", fg = "#515151") dado_r.pack()
rest1 = Label(create, text = "Nome: ", bg = "#eeddff") rest1.pack() rest = Entry(create) rest.pack()
cnpj1 = Label(create, text = "CNPJ: ", bg = "#eeddff") cnpj1.pack() cnpj = Entry(create) cnpj.pack()
tel1 = Label(create, text = "Telefone: ", bg = "#eeddff") tel1.pack() tel = Entry(create) tel.pack()
end1 = Label(create, text = "Endereço: ", bg = "#eeddff") end1.pack() end = Entry(create) end.pack()
info1 = Label(create, text = "Informações adicionais: ", bg = "#eeddff") info1.pack() info = Entry(create) info.pack()
dado_u = Label(create, text = "\n\nDados do usuário ", bg = "#eeddff", font = "Calibri 8", fg = "#515151") dado_u.pack()
usuario1 = Label(create, text = "Nome do usuário: ", bg = "#eeddff") usuario1.pack() us1 = Entry(create) us1.pack()
senha1 = Label(create, text = "Senha: ", bg = "#eeddff") senha1.pack() se1 = Entry(create, show = '*') se1.pack()
nsenha1 = Label(create, text = "Redigite a senha: ", bg = "#eeddff") nsenha1.pack() nse1 = Entry(create, show = '*') nse1.pack()
restricao = Label(create, text = "*Mínimo de 8 caracteres; diferencia maiúsculas de minúsculas\n", font = "Calibri 8", fg = "#515151", bg = "#eeddff") restricao.pack()
def valida() : user = us1.get() password = se1.get() npassword = nse1.get() if len(password) >= 8: if password == npassword: arquivo = open("login.txt", 'a') arquivo.write(user + ' ' + password + '\n') arquivo.close() ok = Label(create, text = "Bem vindo!", bg = "#eeddff") ok.pack() else: errou = Label(create, text = "Ahh, não! Algo está errado!", bg = "#eeddff") errou.pack() finish = Button(create, text = "Pronto", font = "Calibri 10 bold", bg = "#4f8c56", fg = "white", relief = "flat", command = valida) finish.pack() create.pack() #temp.pack()
- --------------------------- Tela categorias *
s = PhotoImage(file = "/root/Larissa/ThinkAboutEat/sushi.gif") sushi = s.subsample(2, 2) p = PhotoImage(file = "/root/Larissa/ThinkAboutEat/pizza.gif") pz = p.subsample(2, 2) san = PhotoImage(file = "/root/Larissa/ThinkAboutEat/sanduiche.gif") sanduba = san.subsample(2, 2) c = PhotoImage(file = "/root/Larissa/ThinkAboutEat/sopa.gif") caldo = c.subsample(2, 2) f = PhotoImage(file = "/root/Larissa/ThinkAboutEat/fastfood.gif") ff = f.subsample(2, 2) h = PhotoImage(file = "/root/Larissa/ThinkAboutEat/hotdog.gif") hot = h.subsample(2, 2) def categoria(): tela_c = Frame(janela) tela_c["bg"] = "#eeddff" home.destroy() comida_japonesa = Button(tela_c, text = "COMIDA JAPONESA", image = sushi, compound = "left", font = "Calibri 15 bold", bg = "#395061", fg = "white", width = 250) comida_japonesa.pack() pizza = Button(tela_c, text = "PIZZA", image = pz, compound = "right", font = "Calibri 15 bold", bg = "#2cb69d", fg = "white", width = 250) pizza.pack() sanduiche = Button(tela_c, text = "SANDUÍCHES", image = sanduba, compound = "left", font = "Calibri 15 bold", bg = "#6cbbe6", fg = "white", width = 250) sanduiche.pack() caldos = Button(tela_c, text = "CALDOS", image = caldo, compound = "right", font = "Calibri 15 bold", bg = "#fed87a", fg = "white", width = 250) caldos.pack() fastfood = Button(tela_c, text = "FAST FOOD", image = ff, compound = "left", font = "Calibri 15 bold", bg = "#2a4350", fg = "white", width = 250) fastfood.pack() hotdog = Button(tela_c, text = "CACHORRO-QUENTE", image = hot, compound = "right", font = "Calibri 15 bold", bg = "#23a487", fg = "white", width = 250) hotdog.pack() tela_c.pack()
- --------------------------- Home *
home = Frame(janela) home["bg"] = "#eeddff" c = PhotoImage(file = "/root/Larissa/ThinkAboutEat/pedido.gif") cestinha = c.subsample(2, 2) ch = PhotoImage(file = "/root/Larissa/ThinkAboutEat/tenho.gif") chef = ch.subsample(2, 2) novo_rest = Button(home, text = "Adicionar restaurante", bg = "white", font = "Calibri 11", relief = "flat", command = criar_rest) pedido = Button(home, image = cestinha, compound = "left", text = "Fazer pedido", font = "Calibri 11", bg = "white", relief = "flat", command = categoria) tenho = Button(home, image = chef, compound = "left", bg = "white", text = "Já tenho um restaurante", font = "Calibri 11", relief = "flat") pedido.pack() novo_rest.pack() tenho.pack() home.pack() janela.mainloop() </syntaxhighlight>
16/06/2017 00:49
<syntaxhighlight lang="py">
- ----------------------------- Deleta o restaurante
def delete_rest(): nome = input() arquivo = open('dados.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('dados.txt', 'w') k = -2; for linha in texto: lista = linha.split() if lista[0] == nome: k = -1 if k != -2: k+=1 if k == -1: arquivo.writelines(linha) if k == 4: k = -1 arquivo.close()
- ------------------------------------ Adiciona algo ao cardápio
def add_card(): nome = input() tipo = input() novo = input() preco = input() arquivo = open('dados.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('dados.txt', 'w') h = 0 g = -1 for linha in texto: lista = linha.split() if lista[0] == nome: g = 0 if tipo == 'entrada': h = 1 elif tipo == 'principal': h = 2 elif tipo == 'sobremesa': h = 3 else: h = 4 if g != -1: g+=1 if g == h: k = len(linha) linha += novo linha += ' ' linha += preco linha += ' ' arquivo.writelines(linha) arquivo.close()
- ---------------------- Deleta algo do cardápio
def del_card(): rest = input() tipo = input() comida = input() arquivo = open('dados.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('dados.txt', 'w') h = 0 g = -2 for linha in texto: lista = linha.split() if lista[0] == rest: g = -1 if tipo == 'entrada': h = 1 elif tipo == 'principal': h = 2 elif tipo == 'sobremesa': h = 3 else: h = 4 v = 0 u = 0 lista2 = [] if g != -2: g+=1 if g == h: s = u = 1 lista1 = linha.split() for i in lista1: if i == comida: v = 1 elif v == 1: v = 0 else: lista2.append(i+' ') lista2.append('\n') if u == 1: arquivo.writelines(lista2) else: arquivo.writelines(linha) arquivo.close()
- ------------------------ Le as informações para criar o restaurante
def read(): lista = [] nome = input() lista.append(nome+' ') cnpj = input() lista.append(cnpj+' ') endereco = input() lista.append(endereco+' ') telefone = input() lista.append(telefone+'\n') return lista
- --------------------------- Criar Restaurante
def criar_rest(): restaurante = read() arquivo = open('dados.txt', 'a') arquivo.writelines(restaurante) entrada = input() precoe = input() principal = input() precop = input() sobremesa = input() precos = input() bebida = input() precob = input() en = [] en.append(entrada+' ') en.append(precoe+'\n') pri = [] pri.append(principal+' ') pri.append(precop+'\n') sob = [] sob.append(sobremesa+' ') sob.append(precos+'\n') be = [] be.append(bebida+' ') be.append(precob+'\n') arquivo.writelines(en) arquivo.writelines(pri) arquivo.writelines(sob) arquivo.writelines(be) arquivo.close()
- ------------------- Procurar Restaurante
def procurar_rest(): nome = input() arquivo = open('dados.txt', 'r') texto = arquivo.readlines() j = 0 for i in texto: lista = i.split() if lista[0] == nome: print(lista) j = 1 break if j == 0: print('Restaurante nao encontrado') arquivo.close()
criar_rest() print("Procure: ") procurar_rest() print("Adicione cardapio: ") add_card() print("Delete cardapio: ") del_card() print("Delete rest: ") delete_rest()
</syntaxhighlight>