<syntaxhighlight lang="py">
19/06/2017 - 15:16
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()