Sem resumo de edição |
Sem resumo de edição |
||
| Linha 1: | Linha 1: | ||
<syntaxhighlight lang="py"> | <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() | |||
#********************************************************************************************************************************************************************************* | |||
17/06/2017 - 22:42 | 17/06/2017 - 22:42 | ||
| Linha 5: | Linha 175: | ||
from tkinter import * | from tkinter import * | ||
#--------------------------------------- Deleta o restaurante | |||
def delete_rest(): | def delete_rest(): | ||
nome = input() | nome = input() | ||
| Linha 23: | Linha 194: | ||
k = -1 | k = -1 | ||
arquivo.close() | arquivo.close() | ||
#--------------------------------------- Adicionar algo ao cardápio | |||
def add_card(): | def add_card(): | ||
nome = input() | nome = input() | ||
| Linha 57: | Linha 229: | ||
arquivo.writelines(linha) | arquivo.writelines(linha) | ||
arquivo.close() | arquivo.close() | ||
#--------------------------------------- Deleta algo do cardápio | |||
def del_card(): | def del_card(): | ||
rest = input() | rest = input() | ||
| Linha 104: | Linha 277: | ||
#--------------------------------------------- Le as informações pra criar o restaurante | |||
def read(): | def read(): | ||
lista = [] | lista = [] | ||
| Linha 117: | Linha 290: | ||
return lista | return lista | ||
#----------------------------------------------- Criar restaurante | |||
def criar_rest(): | def criar_rest(): | ||
restaurante = read() | restaurante = read() | ||
| Linha 148: | Linha 321: | ||
arquivo.close() | arquivo.close() | ||
#---------------------- Procurar Restaurante | |||
def procurar_rest(): | def procurar_rest(): | ||
nome = input() | nome = input() | ||
| Linha 173: | Linha 347: | ||
#delete_rest() | #delete_rest() | ||
#******************************************************************************** | |||
class restaurante(): | class restaurante(): | ||
def __init__(self): | def __init__(self): | ||
| Linha 328: | Linha 503: | ||
************************************************************************************************************************************************* | #************************************************************************************************************************************************* | ||
| Linha 335: | Linha 510: | ||
% 16/06/2017 00:49 | % 16/06/2017 00:49 | ||
#----------------------------- Deleta o restaurante | |||
def delete_rest(): | def delete_rest(): | ||
nome = input() | nome = input() | ||
| Linha 353: | Linha 530: | ||
k = -1 | k = -1 | ||
arquivo.close() | arquivo.close() | ||
#------------------------------------ Adiciona algo ao cardápio | |||
def add_card(): | def add_card(): | ||
nome = input() | nome = input() | ||
| Linha 388: | Linha 565: | ||
arquivo.close() | arquivo.close() | ||
#---------------------- Deleta algo do cardápio | |||
def del_card(): | def del_card(): | ||
rest = input() | rest = input() | ||
| Linha 434: | Linha 612: | ||
#------------------------ Le as informações para criar o restaurante | |||
def read(): | def read(): | ||
lista = [] | lista = [] | ||
| Linha 447: | Linha 625: | ||
return lista | return lista | ||
#--------------------------- Criar Restaurante | |||
def criar_rest(): | def criar_rest(): | ||
restaurante = read() | restaurante = read() | ||
| Linha 477: | Linha 655: | ||
arquivo.writelines(be) | arquivo.writelines(be) | ||
arquivo.close() | arquivo.close() | ||
#------------------- Procurar Restaurante | |||
def procurar_rest(): | def procurar_rest(): | ||
nome = input() | nome = input() | ||
| Linha 502: | Linha 680: | ||
print("Delete rest: ") | print("Delete rest: ") | ||
delete_rest() | delete_rest() | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Edição das 18h17min de 19 de junho de 2017
<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()