Sem resumo de edição Etiqueta: visualeditor |
Sem resumo de edição Etiqueta: visualeditor |
||
| (3 revisões intermediárias por 2 usuários não estão sendo mostradas) | |||
| Linha 1: | Linha 1: | ||
== Fase 2 - Concluída == | |||
<syntaxhighlight lang="python3" line="1"> | |||
#17/07/2017 - 20:36 | |||
from tkinter import * | |||
from functools import partial | |||
from tkinter import ttk | |||
import os.path | |||
dicio = {"Nome" : 0, "Símbolo" : 1, "Número Atômico" : 2, "Massa Atômica" : 3, 0 : "Nome", 1 : "Símbolo", 2 : "Número Atômico", 3 : "Número de Massa"} | |||
#----------------Ler os dados de um elemento | |||
def read() : | |||
alt = Tk() | |||
alt.title("Dados do Elemento") | |||
alt.geometry("350x200+600+250") | |||
lb1 = Label(alt, text = "Nome ").place(x = 20, y = 35) | |||
lb2 = Label(alt, text = "Símbolo ").place(x = 20, y = 55) | |||
lb3 = Label(alt, text = "N° Atômico ").place(x = 20, y = 75) | |||
lb4 = Label(alt, text = "Massa Atômica ").place(x = 20, y = 95) | |||
lb5 = Label(alt, text = "Tipo ").place(x = 20, y = 115) | |||
lista = [] | |||
ed1 = Entry(alt) | |||
ed2 = Entry(alt) | |||
ed3 = Entry(alt) | |||
ed4 = Entry(alt) | |||
ed5 = Entry(alt) | |||
ed1.place(x = 125, y = 35) | |||
ed2.place(x = 125, y = 55) | |||
ed3.place(x = 125, y = 75) | |||
ed4.place(x = 125, y = 95) | |||
ed5.place(x = 125, y = 115) | |||
ok = Button(alt, width = 6, text = "OK") | |||
fechar = Button(alt, width = 6, text = "Fechar", command = alt.destroy) | |||
def get_lista() : | |||
lista.append(ed1.get() + ' ') | |||
lista.append(ed2.get() + ' ') | |||
lista.append(ed3.get() + ' ') | |||
lista.append(ed4.get() + ' ') | |||
lista.append(ed5.get() + '\n') | |||
alt.quit() | |||
ok.place(x = 215, y = 140) | |||
fechar.place(x = 215, y = 170) | |||
ok["command"] = get_lista | |||
alt.mainloop() | |||
alt.destroy() | |||
return lista | |||
#----------------Mostra um elemento | |||
def show(elemento) : | |||
jan = Tk() | |||
jan.title(elemento[0]) | |||
jan["bg"] = "lightgreen" | |||
jan.geometry("300x200+600+250") | |||
for i in range(4) : | |||
Label(jan, text = dicio[i] + ": " + elemento[i], bg = jan["bg"], font = ("Arial", 14)).pack() | |||
bt = Button(jan, text = "Fechar", command = jan.quit).pack() | |||
jan.mainloop() | |||
jan.destroy() | |||
#----------------Testa se senha é valida | |||
def senha() : | |||
alt = Tk() | |||
alt.title("Senha") | |||
alt.geometry("300x200+600+250") | |||
lb = Label(alt, text = "Senha ") | |||
ed = Entry(alt, show = "*") | |||
lb.place(x = 20, y = 75) | |||
ed.place(x = 70, y = 75) | |||
ok = Button(alt, width = 6, text = "OK") | |||
fechar = Button(alt, width = 6, text = "Fechar", command = alt.destroy) | |||
cont=0 | |||
def get_senha() : | |||
nome = ed.get() | |||
if nome != "querocriar123": | |||
Label(alt, text = "Senha incorreta").place(x = 20, y = 105) | |||
else : alt.quit() | |||
ok.place(x = 160, y = 105) | |||
fechar.place(x = 160, y = 135) | |||
ok["command"] = get_senha | |||
alt.mainloop() | |||
alt.destroy() | |||
#----------------Adiciona um elemento | |||
def create(): | |||
senha() | |||
elemento = read() | |||
aux = elemento[0] + elemento[1] + elemento[2] + elemento[3] + elemento[4] | |||
if len(aux) > 5: | |||
arquivo = open('dados.txt', 'r') | |||
flag = True | |||
texto = arquivo.readlines() | |||
arquivo.close() | |||
for i in elemento: | |||
for j in texto: | |||
lista = j.split() | |||
cont = 0 | |||
for k in lista: | |||
if cont < 3: | |||
if i == (k + ' '): flag = False | |||
if flag == False: break | |||
else: break | |||
cont += 1 | |||
if flag == False: break | |||
if flag == False: break | |||
arquivo = open('dados.txt', 'a') | |||
if flag == True: | |||
arquivo.writelines(elemento) | |||
else: | |||
jan = Tk() | |||
jan.title("Elemento Existente") | |||
jan["bg"] = "lightyellow" | |||
jan.geometry("350x200+600+250") | |||
Label(jan, text = "O elemento " + elemento[0] + "já existe", font = ("Arial", 13, "bold"), bg = jan["bg"]).place(x = 50, y = 55) | |||
bt = Button(jan, text = "Fechar", command = jan.quit).place(x = 135, y = 105) | |||
jan.mainloop() | |||
jan.destroy() | |||
arquivo.close() | |||
#----------------Consulta um elemento | |||
def recover() : | |||
alt = Tk() | |||
alt.title("Consultar") | |||
alt["bg"] = "lightyellow" | |||
alt.geometry("300x200+600+250") | |||
Label(alt, text = "A consulta pode ser realizada por:", font = ("Arial", 11, "bold"), bg = alt["bg"]).place(x = 25, y = 15) | |||
Label(alt, text = " Nome", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 35) | |||
Label(alt, text = " Símbolo", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 55) | |||
Label(alt, text = " N° Atômico", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 75) | |||
Label(alt, text = " Massa Atômica", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 95) | |||
ed = Entry(alt) | |||
ed.place(x = 58, y = 125) | |||
ok = Button(alt, width = 5, text = "OK") | |||
ok.place(x = 58, y = 150) | |||
fechar = Button(alt, width = 6, text = "Fechar", command = alt.destroy) | |||
fechar.place(x = 138, y = 150) | |||
#----------------Função que procura por um elemento | |||
def busca() : | |||
nome = ed.get() | |||
if len(nome) > 0: | |||
arquivo = open('dados.txt', 'r') | |||
texto = arquivo.readlines() | |||
for linha in texto : | |||
lista = linha.split() | |||
flag = False | |||
cont = 0 | |||
for x in lista : | |||
if cont == 3 : break | |||
if x == nome : | |||
flag = True | |||
break | |||
cont += 1 | |||
if flag == True : | |||
show(lista) | |||
break | |||
else : | |||
jan = Tk() | |||
jan.title("Elemento não encontrado") | |||
jan["bg"] = "lightyellow" | |||
jan.geometry("350x200+600+250") | |||
arquivo.close() | |||
Label(jan, text = "Deseja criar o elemento " + nome, font = ("Arial", 13, "bold"), bg = jan["bg"]).place(x = 50, y = 35) | |||
ans1 = Button(jan, width = 5, text = "SIM", command = create).place(x = 130, y = 75) | |||
ans2 = Button(jan, width = 5, text = "NAO", command = jan.destroy).place(x = 130, y = 105) | |||
jan.mainloop() | |||
jan.destroy() | |||
arquivo.close() | |||
ok["command"] = busca | |||
alt.mainloop() | |||
alt.destroy() | |||
#----------------Atualiza um elemento | |||
def update() : | |||
alt = Tk() | |||
alt.title("Atualizar") | |||
alt["bg"] = "lightyellow" | |||
alt.geometry("300x200+600+250") | |||
Label(alt, text = "A pesquisa pode ser realizada por:", font = ("Arial", 11, "bold"), bg = alt["bg"]).place(x = 25, y = 15) | |||
Label(alt, text = " Nome", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 35) | |||
Label(alt, text = " Símbolo", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 55) | |||
Label(alt, text = " N° Atômico", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 75) | |||
Label(alt, text = " Massa Atômica", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 95) | |||
ed = Entry(alt) | |||
ed.place(x = 58, y = 125) | |||
ok = Button(alt, width = 6, text = "OK") | |||
ok.place(x = 58, y = 150) | |||
fechar = Button(alt, width = 6, text = "Fechar", command = alt.destroy) | |||
fechar.place(x = 138, y = 150) | |||
aux = "" | |||
#----------------Função que procura por um elemento para o atualizar | |||
def muda(): | |||
nome = ed.get() | |||
if len(nome) > 0 : | |||
arquivo = open('dados.txt', 'r') | |||
texto = arquivo.readlines() | |||
arquivo.close() | |||
arquivo = open('dados.txt', 'a') | |||
flag = False | |||
for linha in texto : | |||
lista = linha.split() | |||
flag1 = False | |||
cont = 0 | |||
for x in lista : | |||
if cont == 3 : break | |||
if x == nome : | |||
flag = flag1 = True | |||
break | |||
cont += 1 | |||
if flag1 == True : | |||
aux = lista[0] + " " + lista[1] + " " + lista[2] + " " + lista[3] + "\n" | |||
show(lista) | |||
lista = read() | |||
arquivo.writelines(lista) | |||
cont += 1 | |||
if flag == False : | |||
jan = Tk() | |||
jan.title("Elemento não encontrado") | |||
jan["bg"] = "lightyellow" | |||
jan.geometry("350x200+600+250") | |||
arquivo.close() | |||
Label(jan, text = "Deseja criar o elemento " + nome, font = ("Arial", 13, "bold"), bg = jan["bg"]).place(x = 50, y = 35) | |||
ans1 = Button(jan, width = 5, text = "SIM", command = create).place(x = 130, y = 75) | |||
ans2 = Button(jan, width = 5, text = "NAO", command = jan.destroy).place(x = 130, y = 105) | |||
jan.mainloop() | |||
jan.destroy() | |||
arquivo = open('dados.txt', 'r') | |||
texto = arquivo.readlines() | |||
arquivo.close() | |||
arquivo = open('dados.txt', 'w') | |||
for i in texto: | |||
if aux != i : | |||
arquivo.writelines(i) | |||
arquivo.close() | |||
ok["command"] = muda | |||
alt.mainloop() | |||
alt.destroy() | |||
#----------------Deleta um elemento | |||
def delete() : | |||
jan = Tk() | |||
jan.title("Deletar") | |||
jan["bg"] = "lightyellow" | |||
jan.geometry("300x200+600+250") | |||
lb = Label(jan, text = "Digite o nome do elemento:", font = ("Arial", 13, "bold"), bg = jan["bg"]) | |||
bt = Button(jan, width = 6, text = "OK") | |||
fecha = Button(jan, width = 6, text = "Fechar", command = jan.destroy) | |||
ed = Entry(jan) | |||
#----------------Função que procura por um elemento para o excluir | |||
def excluir(): | |||
nome = ed.get() | |||
if len(nome) > 0 : | |||
arquivo = open('dados.txt', 'r') | |||
texto = arquivo.readlines() | |||
arquivo.close() | |||
arquivo = open('dados.txt', 'w') | |||
cont = 0 | |||
flag = False | |||
deleted = [] | |||
for linha in texto : | |||
lista = linha.split() | |||
flag1 = False | |||
cont = 0 | |||
for x in lista : | |||
if cont == 3 : break | |||
if x == nome : | |||
flag = flag1 = True | |||
break | |||
cont += 1 | |||
if flag1 == False : | |||
arquivo.writelines(linha) | |||
else : deleted = lista | |||
cont += 1 | |||
if flag == True : | |||
alt = Tk() | |||
alt.title("Deletar") | |||
alt["bg"] = "lightyellow" | |||
alt.geometry("350x220+600+250") | |||
Label(alt, text = "O elemento " + deleted[0] + " foi deletado.", font = ("Arial", 13, "bold"), bg = alt["bg"]).place(x = 30, y = 70) | |||
else : | |||
jan = Tk() | |||
jan.title("Elemento não encontrado") | |||
jan["bg"] = "lightyellow" | |||
jan.geometry("350x200+600+250") | |||
arquivo.close() | |||
Label(jan, text = "Deseja criar o elemento " + nome, font = ("Arial", 13, "bold"), bg = jan["bg"]).place(x = 50, y = 35) | |||
ans1 = Button(jan, width = 5, text = "SIM", command = create).place(x = 130, y = 75) | |||
ans2 = Button(jan, width = 5, text = "NAO", command = jan.destroy).place(x = 130, y = 105) | |||
jan.mainloop() | |||
jan.destroy() | |||
lb.place(x = 30, y = 55) | |||
ed.place(x = 69, y = 85) | |||
bt.place(x = 75, y = 110) | |||
fecha.place(x = 155, y = 110) | |||
bt["command"] = excluir | |||
jan.mainloop() | |||
jan.destroy() | |||
#-----------------Mostra os nao metais | |||
def ver_nao_metais(): | |||
janela = Tk() | |||
janela.title("Não Metais") | |||
janela["bg"] = "lightblue" | |||
janela.geometry("600x300+500+150") | |||
if (os.path.exists('dados.txt') == False) : | |||
Label(janela, text = "Não existe 'Metais'", font = ("Arial", 15, "bold"), bg = janela["bg"]).place(x = 200, y = 90) | |||
else : | |||
tabela = ttk.Treeview(janela, selectmode = 'browse', show = 'headings' , height = 20) | |||
arquivo = open('dados.txt', 'r') | |||
texto = arquivo.readlines() | |||
arquivo.close() | |||
for linha in texto: | |||
lista = linha.split() | |||
if lista[4] == 'Não Metal': | |||
tabela.insert("", 'end', text = "L1", values = (lista[0], lista[1], lista[2], lista[3])) | |||
tabela.pack() | |||
tabela["columns"] = ("1", "2", "3", "4") | |||
tabela['show'] = 'headings' | |||
tabela.column("1", width=150, anchor='c') | |||
tabela.column("2", width=150, anchor='c') | |||
tabela.column("3", width=150, anchor='c') | |||
tabela.column("4", width=150, anchor='c') | |||
tabela.heading("1", text="Nome") | |||
tabela.heading("2", text="Símbolo") | |||
tabela.heading("3", text="Número Atômico") | |||
tabela.heading("4", text="Massa") | |||
#-----------------Mostra os metais | |||
def ver_metais(): | |||
janela = Tk() | |||
janela.title("Metais") | |||
janela["bg"] = "lightblue" | |||
janela.geometry("600x300+500+150") | |||
if (os.path.exists('dados.txt') == False) : | |||
Label(janela, text = "Não existe 'Não Metais'", font = ("Arial", 15, "bold"), bg = janela["bg"]).place(x = 200, y = 90) | |||
else : | |||
tabela = ttk.Treeview(janela, selectmode = 'browse', show = 'headings' , height = 20) | |||
arquivo = open('dados.txt', 'r') | |||
texto = arquivo.readlines() | |||
arquivo.close() | |||
for linha in texto: | |||
lista = linha.split() | |||
if lista[4] == 'Metal': | |||
tabela.insert("", 'end', text = "L1", values = (lista[0], lista[1], lista[2], lista[3])) | |||
tabela.pack() | |||
tabela["columns"] = ("1", "2", "3", "4") | |||
tabela['show'] = 'headings' | |||
tabela.column("1", width=150, anchor='c') | |||
tabela.column("2", width=150, anchor='c') | |||
tabela.column("3", width=150, anchor='c') | |||
tabela.column("4", width=150, anchor='c') | |||
tabela.heading("1", text="Nome") | |||
tabela.heading("2", text="Símbolo") | |||
tabela.heading("3", text="Número Atômico") | |||
tabela.heading("4", text="Massa") | |||
#-----------------Mostra os semimetais | |||
def ver_semimetais(): | |||
janela = Tk() | |||
janela.title("Semimetais") | |||
janela["bg"] = "lightblue" | |||
janela.geometry("600x300+500+150") | |||
if (os.path.exists('dados.txt') == False) : | |||
Label(janela, text = "Não existe 'Semimetais'", font = ("Arial", 15, "bold"), bg = janela["bg"]).place(x = 200, y = 90) | |||
else : | |||
tabela = ttk.Treeview(janela, selectmode = 'browse', show = 'headings' , height = 20) | |||
arquivo = open('dados.txt', 'r') | |||
texto = arquivo.readlines() | |||
arquivo.close() | |||
for linha in texto: | |||
lista = linha.split() | |||
if lista[4] == 'Semimetal': | |||
tabela.insert("", 'end', text = "L1", values = (lista[0], lista[1], lista[2], lista[3])) | |||
tabela.pack() | |||
tabela["columns"] = ("1", "2", "3", "4") | |||
tabela['show'] = 'headings' | |||
tabela.column("1", width=150, anchor='c') | |||
tabela.column("2", width=150, anchor='c') | |||
tabela.column("3", width=150, anchor='c') | |||
tabela.column("4", width=150, anchor='c') | |||
tabela.heading("1", text="Nome") | |||
tabela.heading("2", text="Símbolo") | |||
tabela.heading("3", text="Número Atômico") | |||
tabela.heading("4", text="Massa") | |||
#-----------------Janela principal | |||
root = Tk() | |||
root.title("Alchemy") | |||
root["bg"] = "lightblue" | |||
root.geometry("500x500+500+150") | |||
Label(root, text = "O que você deseja fazer?", font = ("Arial", 15, "bold"), bg = root["bg"]).place(x = 135, y = 40) | |||
criar = Button(root, text = "Criar", width = 7, command = create).place(x = 215, y = 100) | |||
atualizar = Button(root, text = "Atualizar", width = 7, command = update).place(x = 215, y = 130) | |||
deletar = Button(root, text = "Deletar", width = 7, command = delete).place(x = 215, y = 160) | |||
consultar = Button(root, text = "Consultar", width = 7, command = recover).place(x = 215, y = 190) | |||
fechar = Button(root, text = "Fechar", width = 7, command = root.destroy).place(x = 215, y = 220) | |||
Label(root, text = "Listagens", font = ("Arial", 15, "bold"), bg = root["bg"]).place(x = 210, y = 270) | |||
metais = Button(root, text = "Metais", width = 7, command = ver_metais).place(x = 215, y = 310) | |||
nao_metais = Button(root, text = "Não Metais", width = 7, command = ver_nao_metais).place(x = 215, y = 340) | |||
semimetais = Button(root, text = "Semimetais", width = 7, command = ver_semimetais).place(x = 215, y = 370) | |||
root.mainloop() | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="python3" line="1"> | |||
#17/07/2017 - 09:59 | |||
from tkinter import * | |||
from functools import partial | |||
from tkinter import ttk | |||
dicio = {"Nome" : 0, "Símbolo" : 1, "Número Atômico" : 2, "Massa Atômica" : 3, 0 : "Nome", 1 : "Símbolo", 2 : "Número Atômico", 3 : "Número de Massa"} | |||
#----------------Ler os dados de um elemento | |||
def read() : | |||
alt = Tk() | |||
alt.title("Dados do Elemento") | |||
alt.geometry("350x200+600+250") | |||
lb1 = Label(alt, text = "Nome ").place(x = 20, y = 35) | |||
lb2 = Label(alt, text = "Símbolo ").place(x = 20, y = 55) | |||
lb3 = Label(alt, text = "N° Atômico ").place(x = 20, y = 75) | |||
lb4 = Label(alt, text = "Massa Atômica ").place(x = 20, y = 95) | |||
lb5 = Label(alt, text = "Tipo ").place(x = 20, y = 115) | |||
lista = [] | |||
ed1 = Entry(alt) | |||
ed2 = Entry(alt) | |||
ed3 = Entry(alt) | |||
ed4 = Entry(alt) | |||
ed5 = Entry(alt) | |||
ed1.place(x = 125, y = 35) | |||
ed2.place(x = 125, y = 55) | |||
ed3.place(x = 125, y = 75) | |||
ed4.place(x = 125, y = 95) | |||
ed5.place(x = 125, y = 115) | |||
ok = Button(alt, width = 6, text = "OK") | |||
fechar = Button(alt, width = 6, text = "Fechar", command = alt.destroy) | |||
def get_lista() : | |||
lista.append(ed1.get() + ' ') | |||
lista.append(ed2.get() + ' ') | |||
lista.append(ed3.get() + ' ') | |||
lista.append(ed4.get() + ' ') | |||
lista.append(ed5.get() + '\n') | |||
alt.quit() | |||
ok.place(x = 215, y = 140) | |||
fechar.place(x = 215, y = 170) | |||
ok["command"] = get_lista | |||
alt.mainloop() | |||
alt.destroy() | |||
return lista | |||
#----------------Mostra um elemento | |||
def show(elemento) : | |||
jan = Tk() | |||
jan.title(elemento[0]) | |||
jan["bg"] = "lightgreen" | |||
jan.geometry("300x200+600+250") | |||
for i in range(4) : | |||
Label(jan, text = dicio[i] + ": " + elemento[i], bg = jan["bg"], font = ("Arial", 14)).pack() | |||
bt = Button(jan, text = "Fechar", command = jan.quit).pack() | |||
jan.mainloop() | |||
jan.destroy() | |||
#----------------Testa se senha é valida | |||
def senha() : | |||
alt = Tk() | |||
alt.title("Senha") | |||
alt.geometry("300x200+600+250") | |||
lb = Label(alt, text = "Senha ") | |||
ed = Entry(alt, show = "*") | |||
lb.place(x = 20, y = 75) | |||
ed.place(x = 70, y = 75) | |||
ok = Button(alt, width = 6, text = "OK") | |||
fechar = Button(alt, width = 6, text = "Fechar", command = alt.destroy) | |||
cont=0 | |||
def get_senha() : | |||
nome = ed.get() | |||
if nome != "querocriar123": | |||
Label(alt, text = "Senha incorreta").place(x = 20, y = 105) | |||
else : alt.quit() | |||
ok.place(x = 160, y = 105) | |||
fechar.place(x = 160, y = 135) | |||
ok["command"] = get_senha | |||
alt.mainloop() | |||
alt.destroy() | |||
#----------------Adiciona um elemento | |||
def create(): | |||
senha() | |||
elemento = read() | |||
aux = elemento[0] + elemento[1] + elemento[2] + elemento[3] + elemento[4] | |||
if len(aux) > 5: | |||
arquivo = open('dados.txt', 'r') | |||
flag = True | |||
texto = arquivo.readlines() | |||
arquivo.close() | |||
for i in elemento: | |||
for j in texto: | |||
lista = j.split() | |||
cont = 0 | |||
for k in lista: | |||
if cont < 3: | |||
if i == (k + ' '): flag = False | |||
if flag == False: break | |||
else: break | |||
cont += 1 | |||
if flag == False: break | |||
if flag == False: break | |||
arquivo = open('dados.txt', 'a') | |||
if flag == True: | |||
arquivo.writelines(elemento) | |||
else: | |||
jan = Tk() | |||
jan.title("Elemento Existente") | |||
jan["bg"] = "lightyellow" | |||
jan.geometry("350x200+600+250") | |||
Label(jan, text = "O elemento " + elemento[0] + "já existe", font = ("Arial", 13, "bold"), bg = jan["bg"]).place(x = 50, y = 55) | |||
bt = Button(jan, text = "Fechar", command = jan.quit).place(x = 135, y = 105) | |||
jan.mainloop() | |||
jan.destroy() | |||
arquivo.close() | |||
#----------------Consulta um elemento | |||
def recover() : | |||
alt = Tk() | |||
alt.title("Consultar") | |||
alt["bg"] = "lightyellow" | |||
alt.geometry("300x200+600+250") | |||
Label(alt, text = "A consulta pode ser realizada por:", font = ("Arial", 11, "bold"), bg = alt["bg"]).place(x = 25, y = 15) | |||
Label(alt, text = " Nome", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 35) | |||
Label(alt, text = " Símbolo", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 55) | |||
Label(alt, text = " N° Atômico", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 75) | |||
Label(alt, text = " Massa Atômica", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 95) | |||
ed = Entry(alt) | |||
ed.place(x = 58, y = 125) | |||
ok = Button(alt, width = 5, text = "OK") | |||
ok.place(x = 58, y = 150) | |||
fechar = Button(alt, width = 6, text = "Fechar", command = alt.destroy) | |||
fechar.place(x = 138, y = 150) | |||
#----------------Função que procura por um elemento | |||
def busca() : | |||
nome = ed.get() | |||
if len(nome) > 0: | |||
arquivo = open('dados.txt', 'r') | |||
texto = arquivo.readlines() | |||
for linha in texto : | |||
lista = linha.split() | |||
flag = False | |||
cont = 0 | |||
for x in lista : | |||
if cont == 3 : break | |||
if x == nome : | |||
flag = True | |||
break | |||
cont += 1 | |||
if flag == True : | |||
show(lista) | |||
break | |||
else : | |||
jan = Tk() | |||
jan.title("Elemento não encontrado") | |||
jan["bg"] = "lightyellow" | |||
jan.geometry("350x200+600+250") | |||
arquivo.close() | |||
Label(jan, text = "Deseja criar o elemento " + nome, font = ("Arial", 13, "bold"), bg = jan["bg"]).place(x = 50, y = 35) | |||
ans1 = Button(jan, width = 5, text = "SIM", command = create).place(x = 130, y = 75) | |||
ans2 = Button(jan, width = 5, text = "NAO", command = jan.destroy).place(x = 130, y = 105) | |||
jan.mainloop() | |||
jan.destroy() | |||
arquivo.close() | |||
ok["command"] = busca | |||
alt.mainloop() | |||
alt.destroy() | |||
#----------------Atualiza um elemento | |||
def update() : | |||
alt = Tk() | |||
alt.title("Atualizar") | |||
alt["bg"] = "lightyellow" | |||
alt.geometry("300x200+600+250") | |||
Label(alt, text = "A pesquisa pode ser realizada por:", font = ("Arial", 11, "bold"), bg = alt["bg"]).place(x = 25, y = 15) | |||
Label(alt, text = " Nome", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 35) | |||
Label(alt, text = " Símbolo", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 55) | |||
Label(alt, text = " N° Atômico", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 75) | |||
Label(alt, text = " Massa Atômica", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 95) | |||
ed = Entry(alt) | |||
ed.place(x = 58, y = 125) | |||
ok = Button(alt, width = 6, text = "OK") | |||
ok.place(x = 58, y = 150) | |||
fechar = Button(alt, width = 6, text = "Fechar", command = alt.destroy) | |||
fechar.place(x = 138, y = 150) | |||
aux = "" | |||
#----------------Função que procura por um elemento para o atualizar | |||
def muda(): | |||
nome = ed.get() | |||
if len(nome) > 0 : | |||
arquivo = open('dados.txt', 'r') | |||
texto = arquivo.readlines() | |||
arquivo.close() | |||
arquivo = open('dados.txt', 'a') | |||
flag = False | |||
for linha in texto : | |||
lista = linha.split() | |||
flag1 = False | |||
cont = 0 | |||
for x in lista : | |||
if cont == 3 : break | |||
if x == nome : | |||
flag = flag1 = True | |||
break | |||
cont += 1 | |||
if flag1 == True : | |||
aux = lista[0] + " " + lista[1] + " " + lista[2] + " " + lista[3] + "\n" | |||
show(lista) | |||
lista = read() | |||
arquivo.writelines(lista) | |||
cont += 1 | |||
if flag == False : | |||
jan = Tk() | |||
jan.title("Elemento não encontrado") | |||
jan["bg"] = "lightyellow" | |||
jan.geometry("350x200+600+250") | |||
arquivo.close() | |||
Label(jan, text = "Deseja criar o elemento " + nome, font = ("Arial", 13, "bold"), bg = jan["bg"]).place(x = 50, y = 35) | |||
ans1 = Button(jan, width = 5, text = "SIM", command = create).place(x = 130, y = 75) | |||
ans2 = Button(jan, width = 5, text = "NAO", command = jan.destroy).place(x = 130, y = 105) | |||
jan.mainloop() | |||
jan.destroy() | |||
arquivo = open('dados.txt', 'r') | |||
texto = arquivo.readlines() | |||
arquivo.close() | |||
arquivo = open('dados.txt', 'w') | |||
for i in texto: | |||
if aux != i : | |||
arquivo.writelines(i) | |||
arquivo.close() | |||
ok["command"] = muda | |||
alt.mainloop() | |||
alt.destroy() | |||
#----------------Deleta um elemento | |||
def delete() : | |||
jan = Tk() | |||
jan.title("Deletar") | |||
jan["bg"] = "lightyellow" | |||
jan.geometry("300x200+600+250") | |||
lb = Label(jan, text = "Digite o nome do elemento:", font = ("Arial", 13, "bold"), bg = jan["bg"]) | |||
bt = Button(jan, width = 6, text = "OK") | |||
fecha = Button(jan, width = 6, text = "Fechar", command = jan.destroy) | |||
ed = Entry(jan) | |||
#----------------Função que procura por um elemento para o excluir | |||
def excluir(): | |||
nome = ed.get() | |||
if len(nome) > 0 : | |||
arquivo = open('dados.txt', 'r') | |||
texto = arquivo.readlines() | |||
arquivo.close() | |||
arquivo = open('dados.txt', 'w') | |||
cont = 0 | |||
flag = False | |||
deleted = [] | |||
for linha in texto : | |||
lista = linha.split() | |||
flag1 = False | |||
cont = 0 | |||
for x in lista : | |||
if cont == 3 : break | |||
if x == nome : | |||
flag = flag1 = True | |||
break | |||
cont += 1 | |||
if flag1 == False : | |||
arquivo.writelines(linha) | |||
else : deleted = lista | |||
cont += 1 | |||
if flag == True : | |||
alt = Tk() | |||
alt.title("Deletar") | |||
alt["bg"] = "lightyellow" | |||
alt.geometry("350x220+600+250") | |||
Label(alt, text = "O elemento " + deleted[0] + " foi deletado.", font = ("Arial", 13, "bold"), bg = alt["bg"]).place(x = 30, y = 70) | |||
else : | |||
jan = Tk() | |||
jan.title("Elemento não encontrado") | |||
jan["bg"] = "lightyellow" | |||
jan.geometry("350x200+600+250") | |||
arquivo.close() | |||
Label(jan, text = "Deseja criar o elemento " + nome, font = ("Arial", 13, "bold"), bg = jan["bg"]).place(x = 50, y = 35) | |||
ans1 = Button(jan, width = 5, text = "SIM", command = create).place(x = 130, y = 75) | |||
ans2 = Button(jan, width = 5, text = "NAO", command = jan.destroy).place(x = 130, y = 105) | |||
jan.mainloop() | |||
jan.destroy() | |||
lb.place(x = 30, y = 55) | |||
ed.place(x = 69, y = 85) | |||
bt.place(x = 75, y = 110) | |||
fecha.place(x = 155, y = 110) | |||
bt["command"] = excluir | |||
jan.mainloop() | |||
jan.destroy() | |||
#-----------------Mostra os nao metais | |||
def ver_nao_metais(): | |||
janela = Tk() | |||
janela.title("Não Metais") | |||
janela["bg"] = "lightblue" | |||
janela.geometry("600x300+500+150") | |||
tabela = ttk.Treeview(janela, selectmode = 'browse', show = 'headings' , height = 10) | |||
arquivo = open('dados.txt', 'r') | |||
texto = arquivo.readlines() | |||
arquivo.close() | |||
for linha in texto: | |||
lista = linha.split() | |||
if lista[4] == 'Não Metal': | |||
tabela.insert("", 'end', text = "L1", values = (lista[0], lista[1], lista[2], lista[3])) | |||
tabela.pack() | |||
tabela["columns"] = ("1", "2", "3", "4") | |||
tabela['show'] = 'headings' | |||
tabela.column("1", width=150, anchor='c') | |||
tabela.column("2", width=150, anchor='c') | |||
tabela.column("3", width=150, anchor='c') | |||
tabela.column("4", width=150, anchor='c') | |||
tabela.heading("1", text="Nome") | |||
tabela.heading("2", text="Símbolo") | |||
tabela.heading("3", text="Número Atômico") | |||
tabela.heading("4", text="Massa") | |||
#-----------------Mostra os metais | |||
def ver_metais(): | |||
janela = Tk() | |||
janela.title("Metais") | |||
janela["bg"] = "lightblue" | |||
janela.geometry("600x300+500+150") | |||
tabela = ttk.Treeview(janela, selectmode = 'browse', show = 'headings' , height = 10) | |||
arquivo = open('dados.txt', 'r') | |||
texto = arquivo.readlines() | |||
arquivo.close() | |||
for linha in texto: | |||
lista = linha.split() | |||
if lista[4] == 'Metal': | |||
tabela.insert("", 'end', text = "L1", values = (lista[0], lista[1], lista[2], lista[3])) | |||
tabela.pack() | |||
tabela["columns"] = ("1", "2", "3", "4") | |||
tabela['show'] = 'headings' | |||
tabela.column("1", width=150, anchor='c') | |||
tabela.column("2", width=150, anchor='c') | |||
tabela.column("3", width=150, anchor='c') | |||
tabela.column("4", width=150, anchor='c') | |||
tabela.heading("1", text="Nome") | |||
tabela.heading("2", text="Símbolo") | |||
tabela.heading("3", text="Número Atômico") | |||
tabela.heading("4", text="Massa") | |||
#-----------------Mostra os semimetais | |||
def ver_semimetais(): | |||
janela = Tk() | |||
janela.title("Semimetais") | |||
janela["bg"] = "lightblue" | |||
janela.geometry("600x300+500+150") | |||
tabela = ttk.Treeview(janela, selectmode = 'browse', show = 'headings' , height = 10) | |||
arquivo = open('dados.txt', 'r') | |||
texto = arquivo.readlines() | |||
arquivo.close() | |||
for linha in texto: | |||
lista = linha.split() | |||
if lista[4] == 'Semimetal': | |||
tabela.insert("", 'end', text = "L1", values = (lista[0], lista[1], lista[2], lista[3])) | |||
tabela.pack() | |||
tabela["columns"] = ("1", "2", "3", "4") | |||
tabela['show'] = 'headings' | |||
tabela.column("1", width=150, anchor='c') | |||
tabela.column("2", width=150, anchor='c') | |||
tabela.column("3", width=150, anchor='c') | |||
tabela.column("4", width=150, anchor='c') | |||
tabela.heading("1", text="Nome") | |||
tabela.heading("2", text="Símbolo") | |||
tabela.heading("3", text="Número Atômico") | |||
tabela.heading("4", text="Massa") | |||
#-----------------Janela principal | |||
root = Tk() | |||
root.title("Alchemy") | |||
root["bg"] = "lightblue" | |||
root.geometry("500x500+500+150") | |||
Label(root, text = "O que você deseja fazer?", font = ("Arial", 15, "bold"), bg = root["bg"]).place(x = 135, y = 40) | |||
criar = Button(root, text = "Criar", width = 7, command = create).place(x = 215, y = 100) | |||
atualizar = Button(root, text = "Atualizar", width = 7, command = update).place(x = 215, y = 130) | |||
deletar = Button(root, text = "Deletar", width = 7, command = delete).place(x = 215, y = 160) | |||
consultar = Button(root, text = "Consultar", width = 7, command = recover).place(x = 215, y = 190) | |||
fechar = Button(root, text = "Fechar", width = 7, command = quit).place(x = 215, y = 220) | |||
Label(root, text = "Listagens", font = ("Arial", 15, "bold"), bg = root["bg"]).place(x = 210, y = 270) | |||
metais = Button(root, text = "Metais", width = 7, command = ver_metais).place(x = 215, y = 310) | |||
nao_metais = Button(root, text = "Não Metais", width = 7, command = ver_nao_metais).place(x = 215, y = 340) | |||
semimetais = Button(root, text = "Semimetais", width = 7, command = ver_semimetais).place(x = 215, y = 370) | |||
root.mainloop() | |||
root.destroy() | |||
</syntaxhighlight> | |||
== Fase 1 - Concluída == | == Fase 1 - Concluída == | ||
<syntaxhighlight lang="python3"> | <syntaxhighlight lang="python3" line="1"> | ||
#24/06/2017 - 15:16 | #24/06/2017 - 15:16 | ||
| Linha 141: | Linha 1 005: | ||
nome = ed.get() | nome = ed.get() | ||
if len(nome) > 0: | if len(nome) > 0: | ||
arquivo = open('dados.txt', 'r') | arquivo = open('dados.txt', 'r') | ||
texto = arquivo.readlines() | texto = arquivo.readlines() | ||
Edição atual tal como às 23h36min de 17 de julho de 2017
Fase 2 - Concluída
<syntaxhighlight lang="python3" line="1">
- 17/07/2017 - 20:36
from tkinter import * from functools import partial from tkinter import ttk import os.path
dicio = {"Nome" : 0, "Símbolo" : 1, "Número Atômico" : 2, "Massa Atômica" : 3, 0 : "Nome", 1 : "Símbolo", 2 : "Número Atômico", 3 : "Número de Massa"}
- ----------------Ler os dados de um elemento
def read() : alt = Tk() alt.title("Dados do Elemento") alt.geometry("350x200+600+250") lb1 = Label(alt, text = "Nome ").place(x = 20, y = 35) lb2 = Label(alt, text = "Símbolo ").place(x = 20, y = 55) lb3 = Label(alt, text = "N° Atômico ").place(x = 20, y = 75) lb4 = Label(alt, text = "Massa Atômica ").place(x = 20, y = 95) lb5 = Label(alt, text = "Tipo ").place(x = 20, y = 115) lista = [] ed1 = Entry(alt) ed2 = Entry(alt) ed3 = Entry(alt) ed4 = Entry(alt) ed5 = Entry(alt) ed1.place(x = 125, y = 35) ed2.place(x = 125, y = 55) ed3.place(x = 125, y = 75) ed4.place(x = 125, y = 95) ed5.place(x = 125, y = 115) ok = Button(alt, width = 6, text = "OK") fechar = Button(alt, width = 6, text = "Fechar", command = alt.destroy) def get_lista() : lista.append(ed1.get() + ' ') lista.append(ed2.get() + ' ') lista.append(ed3.get() + ' ') lista.append(ed4.get() + ' ') lista.append(ed5.get() + '\n') alt.quit() ok.place(x = 215, y = 140) fechar.place(x = 215, y = 170) ok["command"] = get_lista alt.mainloop() alt.destroy() return lista
- ----------------Mostra um elemento
def show(elemento) : jan = Tk() jan.title(elemento[0]) jan["bg"] = "lightgreen" jan.geometry("300x200+600+250") for i in range(4) : Label(jan, text = dicio[i] + ": " + elemento[i], bg = jan["bg"], font = ("Arial", 14)).pack() bt = Button(jan, text = "Fechar", command = jan.quit).pack() jan.mainloop() jan.destroy()
- ----------------Testa se senha é valida
def senha() : alt = Tk() alt.title("Senha") alt.geometry("300x200+600+250") lb = Label(alt, text = "Senha ") ed = Entry(alt, show = "*") lb.place(x = 20, y = 75) ed.place(x = 70, y = 75) ok = Button(alt, width = 6, text = "OK") fechar = Button(alt, width = 6, text = "Fechar", command = alt.destroy) cont=0 def get_senha() : nome = ed.get() if nome != "querocriar123": Label(alt, text = "Senha incorreta").place(x = 20, y = 105) else : alt.quit() ok.place(x = 160, y = 105) fechar.place(x = 160, y = 135) ok["command"] = get_senha alt.mainloop() alt.destroy()
- ----------------Adiciona um elemento
def create(): senha() elemento = read() aux = elemento[0] + elemento[1] + elemento[2] + elemento[3] + elemento[4] if len(aux) > 5: arquivo = open('dados.txt', 'r') flag = True texto = arquivo.readlines() arquivo.close() for i in elemento: for j in texto: lista = j.split() cont = 0 for k in lista: if cont < 3: if i == (k + ' '): flag = False if flag == False: break else: break cont += 1 if flag == False: break if flag == False: break arquivo = open('dados.txt', 'a') if flag == True: arquivo.writelines(elemento) else: jan = Tk() jan.title("Elemento Existente") jan["bg"] = "lightyellow" jan.geometry("350x200+600+250") Label(jan, text = "O elemento " + elemento[0] + "já existe", font = ("Arial", 13, "bold"), bg = jan["bg"]).place(x = 50, y = 55) bt = Button(jan, text = "Fechar", command = jan.quit).place(x = 135, y = 105) jan.mainloop() jan.destroy() arquivo.close()
- ----------------Consulta um elemento
def recover() : alt = Tk() alt.title("Consultar") alt["bg"] = "lightyellow" alt.geometry("300x200+600+250") Label(alt, text = "A consulta pode ser realizada por:", font = ("Arial", 11, "bold"), bg = alt["bg"]).place(x = 25, y = 15) Label(alt, text = " Nome", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 35) Label(alt, text = " Símbolo", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 55) Label(alt, text = " N° Atômico", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 75) Label(alt, text = " Massa Atômica", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 95) ed = Entry(alt) ed.place(x = 58, y = 125) ok = Button(alt, width = 5, text = "OK") ok.place(x = 58, y = 150) fechar = Button(alt, width = 6, text = "Fechar", command = alt.destroy) fechar.place(x = 138, y = 150)
#----------------Função que procura por um elemento def busca() : nome = ed.get() if len(nome) > 0: arquivo = open('dados.txt', 'r') texto = arquivo.readlines() for linha in texto : lista = linha.split() flag = False cont = 0 for x in lista : if cont == 3 : break if x == nome : flag = True break cont += 1 if flag == True : show(lista) break else : jan = Tk() jan.title("Elemento não encontrado") jan["bg"] = "lightyellow" jan.geometry("350x200+600+250") arquivo.close() Label(jan, text = "Deseja criar o elemento " + nome, font = ("Arial", 13, "bold"), bg = jan["bg"]).place(x = 50, y = 35) ans1 = Button(jan, width = 5, text = "SIM", command = create).place(x = 130, y = 75) ans2 = Button(jan, width = 5, text = "NAO", command = jan.destroy).place(x = 130, y = 105) jan.mainloop() jan.destroy() arquivo.close()
ok["command"] = busca alt.mainloop() alt.destroy()
- ----------------Atualiza um elemento
def update() : alt = Tk() alt.title("Atualizar") alt["bg"] = "lightyellow" alt.geometry("300x200+600+250") Label(alt, text = "A pesquisa pode ser realizada por:", font = ("Arial", 11, "bold"), bg = alt["bg"]).place(x = 25, y = 15) Label(alt, text = " Nome", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 35) Label(alt, text = " Símbolo", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 55) Label(alt, text = " N° Atômico", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 75) Label(alt, text = " Massa Atômica", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 95) ed = Entry(alt) ed.place(x = 58, y = 125) ok = Button(alt, width = 6, text = "OK") ok.place(x = 58, y = 150) fechar = Button(alt, width = 6, text = "Fechar", command = alt.destroy) fechar.place(x = 138, y = 150) aux = ""
#----------------Função que procura por um elemento para o atualizar def muda(): nome = ed.get() if len(nome) > 0 : arquivo = open('dados.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('dados.txt', 'a') flag = False for linha in texto : lista = linha.split() flag1 = False cont = 0 for x in lista : if cont == 3 : break if x == nome : flag = flag1 = True break cont += 1 if flag1 == True : aux = lista[0] + " " + lista[1] + " " + lista[2] + " " + lista[3] + "\n" show(lista) lista = read() arquivo.writelines(lista) cont += 1 if flag == False : jan = Tk() jan.title("Elemento não encontrado") jan["bg"] = "lightyellow" jan.geometry("350x200+600+250") arquivo.close() Label(jan, text = "Deseja criar o elemento " + nome, font = ("Arial", 13, "bold"), bg = jan["bg"]).place(x = 50, y = 35) ans1 = Button(jan, width = 5, text = "SIM", command = create).place(x = 130, y = 75) ans2 = Button(jan, width = 5, text = "NAO", command = jan.destroy).place(x = 130, y = 105) jan.mainloop() jan.destroy()
arquivo = open('dados.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('dados.txt', 'w') for i in texto: if aux != i : arquivo.writelines(i) arquivo.close()
ok["command"] = muda alt.mainloop() alt.destroy()
- ----------------Deleta um elemento
def delete() : jan = Tk() jan.title("Deletar") jan["bg"] = "lightyellow" jan.geometry("300x200+600+250") lb = Label(jan, text = "Digite o nome do elemento:", font = ("Arial", 13, "bold"), bg = jan["bg"]) bt = Button(jan, width = 6, text = "OK") fecha = Button(jan, width = 6, text = "Fechar", command = jan.destroy) ed = Entry(jan)
#----------------Função que procura por um elemento para o excluir def excluir(): nome = ed.get() if len(nome) > 0 : arquivo = open('dados.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('dados.txt', 'w') cont = 0 flag = False deleted = [] for linha in texto : lista = linha.split() flag1 = False cont = 0 for x in lista : if cont == 3 : break if x == nome : flag = flag1 = True break cont += 1 if flag1 == False : arquivo.writelines(linha) else : deleted = lista cont += 1 if flag == True : alt = Tk() alt.title("Deletar") alt["bg"] = "lightyellow" alt.geometry("350x220+600+250") Label(alt, text = "O elemento " + deleted[0] + " foi deletado.", font = ("Arial", 13, "bold"), bg = alt["bg"]).place(x = 30, y = 70) else : jan = Tk() jan.title("Elemento não encontrado") jan["bg"] = "lightyellow" jan.geometry("350x200+600+250") arquivo.close() Label(jan, text = "Deseja criar o elemento " + nome, font = ("Arial", 13, "bold"), bg = jan["bg"]).place(x = 50, y = 35) ans1 = Button(jan, width = 5, text = "SIM", command = create).place(x = 130, y = 75) ans2 = Button(jan, width = 5, text = "NAO", command = jan.destroy).place(x = 130, y = 105) jan.mainloop() jan.destroy()
lb.place(x = 30, y = 55) ed.place(x = 69, y = 85) bt.place(x = 75, y = 110) fecha.place(x = 155, y = 110) bt["command"] = excluir jan.mainloop() jan.destroy()
- -----------------Mostra os nao metais
def ver_nao_metais(): janela = Tk() janela.title("Não Metais") janela["bg"] = "lightblue" janela.geometry("600x300+500+150")
if (os.path.exists('dados.txt') == False) : Label(janela, text = "Não existe 'Metais'", font = ("Arial", 15, "bold"), bg = janela["bg"]).place(x = 200, y = 90) else : tabela = ttk.Treeview(janela, selectmode = 'browse', show = 'headings' , height = 20) arquivo = open('dados.txt', 'r') texto = arquivo.readlines() arquivo.close()
for linha in texto: lista = linha.split() if lista[4] == 'Não Metal': tabela.insert("", 'end', text = "L1", values = (lista[0], lista[1], lista[2], lista[3]))
tabela.pack() tabela["columns"] = ("1", "2", "3", "4") tabela['show'] = 'headings'
tabela.column("1", width=150, anchor='c') tabela.column("2", width=150, anchor='c') tabela.column("3", width=150, anchor='c') tabela.column("4", width=150, anchor='c')
tabela.heading("1", text="Nome") tabela.heading("2", text="Símbolo") tabela.heading("3", text="Número Atômico") tabela.heading("4", text="Massa")
- -----------------Mostra os metais
def ver_metais(): janela = Tk() janela.title("Metais") janela["bg"] = "lightblue" janela.geometry("600x300+500+150")
if (os.path.exists('dados.txt') == False) : Label(janela, text = "Não existe 'Não Metais'", font = ("Arial", 15, "bold"), bg = janela["bg"]).place(x = 200, y = 90) else : tabela = ttk.Treeview(janela, selectmode = 'browse', show = 'headings' , height = 20) arquivo = open('dados.txt', 'r') texto = arquivo.readlines() arquivo.close()
for linha in texto: lista = linha.split() if lista[4] == 'Metal': tabela.insert("", 'end', text = "L1", values = (lista[0], lista[1], lista[2], lista[3]))
tabela.pack() tabela["columns"] = ("1", "2", "3", "4") tabela['show'] = 'headings'
tabela.column("1", width=150, anchor='c') tabela.column("2", width=150, anchor='c') tabela.column("3", width=150, anchor='c') tabela.column("4", width=150, anchor='c')
tabela.heading("1", text="Nome") tabela.heading("2", text="Símbolo") tabela.heading("3", text="Número Atômico") tabela.heading("4", text="Massa")
- -----------------Mostra os semimetais
def ver_semimetais(): janela = Tk() janela.title("Semimetais") janela["bg"] = "lightblue" janela.geometry("600x300+500+150")
if (os.path.exists('dados.txt') == False) : Label(janela, text = "Não existe 'Semimetais'", font = ("Arial", 15, "bold"), bg = janela["bg"]).place(x = 200, y = 90) else : tabela = ttk.Treeview(janela, selectmode = 'browse', show = 'headings' , height = 20) arquivo = open('dados.txt', 'r') texto = arquivo.readlines() arquivo.close()
for linha in texto: lista = linha.split() if lista[4] == 'Semimetal': tabela.insert("", 'end', text = "L1", values = (lista[0], lista[1], lista[2], lista[3]))
tabela.pack() tabela["columns"] = ("1", "2", "3", "4") tabela['show'] = 'headings'
tabela.column("1", width=150, anchor='c') tabela.column("2", width=150, anchor='c') tabela.column("3", width=150, anchor='c') tabela.column("4", width=150, anchor='c')
tabela.heading("1", text="Nome") tabela.heading("2", text="Símbolo") tabela.heading("3", text="Número Atômico") tabela.heading("4", text="Massa")
- -----------------Janela principal
root = Tk() root.title("Alchemy") root["bg"] = "lightblue" root.geometry("500x500+500+150") Label(root, text = "O que você deseja fazer?", font = ("Arial", 15, "bold"), bg = root["bg"]).place(x = 135, y = 40) criar = Button(root, text = "Criar", width = 7, command = create).place(x = 215, y = 100) atualizar = Button(root, text = "Atualizar", width = 7, command = update).place(x = 215, y = 130) deletar = Button(root, text = "Deletar", width = 7, command = delete).place(x = 215, y = 160) consultar = Button(root, text = "Consultar", width = 7, command = recover).place(x = 215, y = 190) fechar = Button(root, text = "Fechar", width = 7, command = root.destroy).place(x = 215, y = 220) Label(root, text = "Listagens", font = ("Arial", 15, "bold"), bg = root["bg"]).place(x = 210, y = 270) metais = Button(root, text = "Metais", width = 7, command = ver_metais).place(x = 215, y = 310) nao_metais = Button(root, text = "Não Metais", width = 7, command = ver_nao_metais).place(x = 215, y = 340) semimetais = Button(root, text = "Semimetais", width = 7, command = ver_semimetais).place(x = 215, y = 370) root.mainloop() </syntaxhighlight>
<syntaxhighlight lang="python3" line="1">
- 17/07/2017 - 09:59
from tkinter import * from functools import partial from tkinter import ttk
dicio = {"Nome" : 0, "Símbolo" : 1, "Número Atômico" : 2, "Massa Atômica" : 3, 0 : "Nome", 1 : "Símbolo", 2 : "Número Atômico", 3 : "Número de Massa"}
- ----------------Ler os dados de um elemento
def read() : alt = Tk() alt.title("Dados do Elemento") alt.geometry("350x200+600+250") lb1 = Label(alt, text = "Nome ").place(x = 20, y = 35) lb2 = Label(alt, text = "Símbolo ").place(x = 20, y = 55) lb3 = Label(alt, text = "N° Atômico ").place(x = 20, y = 75) lb4 = Label(alt, text = "Massa Atômica ").place(x = 20, y = 95) lb5 = Label(alt, text = "Tipo ").place(x = 20, y = 115) lista = [] ed1 = Entry(alt) ed2 = Entry(alt) ed3 = Entry(alt) ed4 = Entry(alt) ed5 = Entry(alt) ed1.place(x = 125, y = 35) ed2.place(x = 125, y = 55) ed3.place(x = 125, y = 75) ed4.place(x = 125, y = 95) ed5.place(x = 125, y = 115) ok = Button(alt, width = 6, text = "OK") fechar = Button(alt, width = 6, text = "Fechar", command = alt.destroy) def get_lista() : lista.append(ed1.get() + ' ') lista.append(ed2.get() + ' ') lista.append(ed3.get() + ' ') lista.append(ed4.get() + ' ') lista.append(ed5.get() + '\n') alt.quit() ok.place(x = 215, y = 140) fechar.place(x = 215, y = 170) ok["command"] = get_lista alt.mainloop() alt.destroy() return lista
- ----------------Mostra um elemento
def show(elemento) : jan = Tk() jan.title(elemento[0]) jan["bg"] = "lightgreen" jan.geometry("300x200+600+250") for i in range(4) : Label(jan, text = dicio[i] + ": " + elemento[i], bg = jan["bg"], font = ("Arial", 14)).pack() bt = Button(jan, text = "Fechar", command = jan.quit).pack() jan.mainloop() jan.destroy()
- ----------------Testa se senha é valida
def senha() : alt = Tk() alt.title("Senha") alt.geometry("300x200+600+250") lb = Label(alt, text = "Senha ") ed = Entry(alt, show = "*") lb.place(x = 20, y = 75) ed.place(x = 70, y = 75) ok = Button(alt, width = 6, text = "OK") fechar = Button(alt, width = 6, text = "Fechar", command = alt.destroy) cont=0 def get_senha() : nome = ed.get() if nome != "querocriar123": Label(alt, text = "Senha incorreta").place(x = 20, y = 105) else : alt.quit() ok.place(x = 160, y = 105) fechar.place(x = 160, y = 135) ok["command"] = get_senha alt.mainloop() alt.destroy()
- ----------------Adiciona um elemento
def create(): senha() elemento = read() aux = elemento[0] + elemento[1] + elemento[2] + elemento[3] + elemento[4] if len(aux) > 5: arquivo = open('dados.txt', 'r') flag = True texto = arquivo.readlines() arquivo.close() for i in elemento: for j in texto: lista = j.split() cont = 0 for k in lista: if cont < 3: if i == (k + ' '): flag = False if flag == False: break else: break cont += 1 if flag == False: break if flag == False: break arquivo = open('dados.txt', 'a') if flag == True: arquivo.writelines(elemento) else: jan = Tk() jan.title("Elemento Existente") jan["bg"] = "lightyellow" jan.geometry("350x200+600+250") Label(jan, text = "O elemento " + elemento[0] + "já existe", font = ("Arial", 13, "bold"), bg = jan["bg"]).place(x = 50, y = 55) bt = Button(jan, text = "Fechar", command = jan.quit).place(x = 135, y = 105) jan.mainloop() jan.destroy() arquivo.close()
- ----------------Consulta um elemento
def recover() : alt = Tk() alt.title("Consultar") alt["bg"] = "lightyellow" alt.geometry("300x200+600+250") Label(alt, text = "A consulta pode ser realizada por:", font = ("Arial", 11, "bold"), bg = alt["bg"]).place(x = 25, y = 15) Label(alt, text = " Nome", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 35) Label(alt, text = " Símbolo", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 55) Label(alt, text = " N° Atômico", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 75) Label(alt, text = " Massa Atômica", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 95) ed = Entry(alt) ed.place(x = 58, y = 125) ok = Button(alt, width = 5, text = "OK") ok.place(x = 58, y = 150) fechar = Button(alt, width = 6, text = "Fechar", command = alt.destroy) fechar.place(x = 138, y = 150)
#----------------Função que procura por um elemento def busca() : nome = ed.get() if len(nome) > 0: arquivo = open('dados.txt', 'r') texto = arquivo.readlines() for linha in texto : lista = linha.split() flag = False cont = 0 for x in lista : if cont == 3 : break if x == nome : flag = True break cont += 1 if flag == True : show(lista) break else : jan = Tk() jan.title("Elemento não encontrado") jan["bg"] = "lightyellow" jan.geometry("350x200+600+250") arquivo.close() Label(jan, text = "Deseja criar o elemento " + nome, font = ("Arial", 13, "bold"), bg = jan["bg"]).place(x = 50, y = 35) ans1 = Button(jan, width = 5, text = "SIM", command = create).place(x = 130, y = 75) ans2 = Button(jan, width = 5, text = "NAO", command = jan.destroy).place(x = 130, y = 105) jan.mainloop() jan.destroy() arquivo.close()
ok["command"] = busca alt.mainloop() alt.destroy()
- ----------------Atualiza um elemento
def update() : alt = Tk() alt.title("Atualizar") alt["bg"] = "lightyellow" alt.geometry("300x200+600+250") Label(alt, text = "A pesquisa pode ser realizada por:", font = ("Arial", 11, "bold"), bg = alt["bg"]).place(x = 25, y = 15) Label(alt, text = " Nome", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 35) Label(alt, text = " Símbolo", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 55) Label(alt, text = " N° Atômico", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 75) Label(alt, text = " Massa Atômica", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 95) ed = Entry(alt) ed.place(x = 58, y = 125) ok = Button(alt, width = 6, text = "OK") ok.place(x = 58, y = 150) fechar = Button(alt, width = 6, text = "Fechar", command = alt.destroy) fechar.place(x = 138, y = 150) aux = ""
#----------------Função que procura por um elemento para o atualizar def muda(): nome = ed.get() if len(nome) > 0 : arquivo = open('dados.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('dados.txt', 'a') flag = False for linha in texto : lista = linha.split() flag1 = False cont = 0 for x in lista : if cont == 3 : break if x == nome : flag = flag1 = True break cont += 1 if flag1 == True : aux = lista[0] + " " + lista[1] + " " + lista[2] + " " + lista[3] + "\n" show(lista) lista = read() arquivo.writelines(lista) cont += 1 if flag == False : jan = Tk() jan.title("Elemento não encontrado") jan["bg"] = "lightyellow" jan.geometry("350x200+600+250") arquivo.close() Label(jan, text = "Deseja criar o elemento " + nome, font = ("Arial", 13, "bold"), bg = jan["bg"]).place(x = 50, y = 35) ans1 = Button(jan, width = 5, text = "SIM", command = create).place(x = 130, y = 75) ans2 = Button(jan, width = 5, text = "NAO", command = jan.destroy).place(x = 130, y = 105) jan.mainloop() jan.destroy()
arquivo = open('dados.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('dados.txt', 'w') for i in texto: if aux != i : arquivo.writelines(i) arquivo.close()
ok["command"] = muda alt.mainloop() alt.destroy()
- ----------------Deleta um elemento
def delete() : jan = Tk() jan.title("Deletar") jan["bg"] = "lightyellow" jan.geometry("300x200+600+250") lb = Label(jan, text = "Digite o nome do elemento:", font = ("Arial", 13, "bold"), bg = jan["bg"]) bt = Button(jan, width = 6, text = "OK") fecha = Button(jan, width = 6, text = "Fechar", command = jan.destroy) ed = Entry(jan)
#----------------Função que procura por um elemento para o excluir def excluir(): nome = ed.get() if len(nome) > 0 : arquivo = open('dados.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('dados.txt', 'w') cont = 0 flag = False deleted = [] for linha in texto : lista = linha.split() flag1 = False cont = 0 for x in lista : if cont == 3 : break if x == nome : flag = flag1 = True break cont += 1 if flag1 == False : arquivo.writelines(linha) else : deleted = lista cont += 1 if flag == True : alt = Tk() alt.title("Deletar") alt["bg"] = "lightyellow" alt.geometry("350x220+600+250") Label(alt, text = "O elemento " + deleted[0] + " foi deletado.", font = ("Arial", 13, "bold"), bg = alt["bg"]).place(x = 30, y = 70) else : jan = Tk() jan.title("Elemento não encontrado") jan["bg"] = "lightyellow" jan.geometry("350x200+600+250") arquivo.close() Label(jan, text = "Deseja criar o elemento " + nome, font = ("Arial", 13, "bold"), bg = jan["bg"]).place(x = 50, y = 35) ans1 = Button(jan, width = 5, text = "SIM", command = create).place(x = 130, y = 75) ans2 = Button(jan, width = 5, text = "NAO", command = jan.destroy).place(x = 130, y = 105) jan.mainloop() jan.destroy()
lb.place(x = 30, y = 55) ed.place(x = 69, y = 85) bt.place(x = 75, y = 110) fecha.place(x = 155, y = 110) bt["command"] = excluir jan.mainloop() jan.destroy()
- -----------------Mostra os nao metais
def ver_nao_metais(): janela = Tk() janela.title("Não Metais") janela["bg"] = "lightblue" janela.geometry("600x300+500+150") tabela = ttk.Treeview(janela, selectmode = 'browse', show = 'headings' , height = 10)
arquivo = open('dados.txt', 'r') texto = arquivo.readlines() arquivo.close()
for linha in texto: lista = linha.split() if lista[4] == 'Não Metal': tabela.insert("", 'end', text = "L1", values = (lista[0], lista[1], lista[2], lista[3]))
tabela.pack() tabela["columns"] = ("1", "2", "3", "4") tabela['show'] = 'headings'
tabela.column("1", width=150, anchor='c') tabela.column("2", width=150, anchor='c') tabela.column("3", width=150, anchor='c') tabela.column("4", width=150, anchor='c')
tabela.heading("1", text="Nome") tabela.heading("2", text="Símbolo") tabela.heading("3", text="Número Atômico") tabela.heading("4", text="Massa")
- -----------------Mostra os metais
def ver_metais(): janela = Tk() janela.title("Metais") janela["bg"] = "lightblue" janela.geometry("600x300+500+150") tabela = ttk.Treeview(janela, selectmode = 'browse', show = 'headings' , height = 10)
arquivo = open('dados.txt', 'r') texto = arquivo.readlines() arquivo.close()
for linha in texto: lista = linha.split() if lista[4] == 'Metal': tabela.insert("", 'end', text = "L1", values = (lista[0], lista[1], lista[2], lista[3]))
tabela.pack() tabela["columns"] = ("1", "2", "3", "4") tabela['show'] = 'headings'
tabela.column("1", width=150, anchor='c') tabela.column("2", width=150, anchor='c') tabela.column("3", width=150, anchor='c') tabela.column("4", width=150, anchor='c')
tabela.heading("1", text="Nome") tabela.heading("2", text="Símbolo") tabela.heading("3", text="Número Atômico") tabela.heading("4", text="Massa")
- -----------------Mostra os semimetais
def ver_semimetais(): janela = Tk() janela.title("Semimetais") janela["bg"] = "lightblue" janela.geometry("600x300+500+150") tabela = ttk.Treeview(janela, selectmode = 'browse', show = 'headings' , height = 10)
arquivo = open('dados.txt', 'r') texto = arquivo.readlines() arquivo.close()
for linha in texto: lista = linha.split() if lista[4] == 'Semimetal': tabela.insert("", 'end', text = "L1", values = (lista[0], lista[1], lista[2], lista[3]))
tabela.pack() tabela["columns"] = ("1", "2", "3", "4") tabela['show'] = 'headings'
tabela.column("1", width=150, anchor='c') tabela.column("2", width=150, anchor='c') tabela.column("3", width=150, anchor='c') tabela.column("4", width=150, anchor='c')
tabela.heading("1", text="Nome") tabela.heading("2", text="Símbolo") tabela.heading("3", text="Número Atômico") tabela.heading("4", text="Massa")
- -----------------Janela principal
root = Tk() root.title("Alchemy") root["bg"] = "lightblue" root.geometry("500x500+500+150") Label(root, text = "O que você deseja fazer?", font = ("Arial", 15, "bold"), bg = root["bg"]).place(x = 135, y = 40) criar = Button(root, text = "Criar", width = 7, command = create).place(x = 215, y = 100) atualizar = Button(root, text = "Atualizar", width = 7, command = update).place(x = 215, y = 130) deletar = Button(root, text = "Deletar", width = 7, command = delete).place(x = 215, y = 160) consultar = Button(root, text = "Consultar", width = 7, command = recover).place(x = 215, y = 190) fechar = Button(root, text = "Fechar", width = 7, command = quit).place(x = 215, y = 220) Label(root, text = "Listagens", font = ("Arial", 15, "bold"), bg = root["bg"]).place(x = 210, y = 270) metais = Button(root, text = "Metais", width = 7, command = ver_metais).place(x = 215, y = 310) nao_metais = Button(root, text = "Não Metais", width = 7, command = ver_nao_metais).place(x = 215, y = 340) semimetais = Button(root, text = "Semimetais", width = 7, command = ver_semimetais).place(x = 215, y = 370) root.mainloop() root.destroy()
</syntaxhighlight>
Fase 1 - Concluída
<syntaxhighlight lang="python3" line="1">
- 24/06/2017 - 15:16
from tkinter import * from functools import partial
dicio = {"Nome" : 0, "Símbolo" : 1, "Número Atômico" : 2, "Massa Atômica" : 3, 0 : "Nome", 1 : "Símbolo", 2 : "Número Atômico", 3 : "Número de Massa"}
- ----------------Ler os dados de um elemento
def read() : alt = Tk() alt.title("Dados do Elemento") alt.geometry("350x200+600+250") lb1 = Label(alt, text = "Nome ").place(x = 20, y = 35) lb2 = Label(alt, text = "Símbolo ").place(x = 20, y = 55) lb3 = Label(alt, text = "N° Atômico ").place(x = 20, y = 75) lb4 = Label(alt, text = "Massa Atômica ").place(x = 20, y = 95) lista = [] ed1 = Entry(alt) ed2 = Entry(alt) ed3 = Entry(alt) ed4 = Entry(alt) ed1.place(x = 125, y = 35) ed2.place(x = 125, y = 55) ed3.place(x = 125, y = 75) ed4.place(x = 125, y = 95) ok = Button(alt, width = 6, text = "OK") fechar = Button(alt, width = 6, text = "Fechar", command = alt.destroy) def get_lista() : lista.append(ed1.get() + ' ') lista.append(ed2.get() + ' ') lista.append(ed3.get() + ' ') lista.append(ed4.get() + '\n') alt.quit() ok.place(x = 215, y = 120) fechar.place(x = 215, y = 150) ok["command"] = get_lista alt.mainloop() alt.destroy() return lista
- ----------------Mostra um elemento
def show(elemento) : jan = Tk() jan.title(elemento[0]) jan["bg"] = "lightgreen" jan.geometry("300x200+600+250") for i in range(4) : Label(jan, text = dicio[i] + ": " + elemento[i], bg = jan["bg"], font = ("Arial", 14)).pack() bt = Button(jan, text = "Fechar", command = jan.quit).pack() jan.mainloop() jan.destroy()
- ----------------Testa se senha é valida
def senha() : alt = Tk() alt.title("Senha") alt.geometry("300x200+600+250") lb = Label(alt, text = "Senha ") ed = Entry(alt, show = "*") lb.place(x = 20, y = 75) ed.place(x = 70, y = 75) ok = Button(alt, width = 6, text = "OK") fechar = Button(alt, width = 6, text = "Fechar", command = alt.destroy) cont=0 def get_senha() : nome = ed.get() if nome != "querocriar123": Label(alt, text = "Senha incorreta").place(x = 20, y = 105) else : alt.quit() ok.place(x = 160, y = 105) fechar.place(x = 160, y = 135) ok["command"] = get_senha alt.mainloop() alt.destroy()
- ----------------Adiciona um elemento
def create(): senha() elemento = read() aux = elemento[0] + elemento[1] + elemento[2] + elemento[3] if len(aux) > 4: arquivo = open('dados.txt', 'r') flag = True texto = arquivo.readlines() arquivo.close() for i in elemento: for j in texto: lista = j.split() cont = 0 for k in lista: if cont < 3: if i == (k + ' '): flag = False if flag == False: break else: break cont += 1 if flag == False: break if flag == False: break arquivo = open('dados.txt', 'a') if flag == True: arquivo.writelines(elemento) else: jan = Tk() jan.title("Elemento Existente") jan["bg"] = "lightyellow" jan.geometry("350x200+600+250") Label(jan, text = "O elemento " + elemento[0] + "já existe", font = ("Arial", 13, "bold"), bg = jan["bg"]).place(x = 50, y = 55) bt = Button(jan, text = "Fechar", command = jan.quit).place(x = 135, y = 105) jan.mainloop() jan.destroy() arquivo.close()
- ----------------Consulta um elemento
def recover() : alt = Tk() alt.title("Consultar") alt["bg"] = "lightyellow" alt.geometry("300x200+600+250") Label(alt, text = "A consulta pode ser realizada por:", font = ("Arial", 11, "bold"), bg = alt["bg"]).place(x = 25, y = 15) Label(alt, text = " Nome", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 35) Label(alt, text = " Símbolo", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 55) Label(alt, text = " N° Atômico", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 75) Label(alt, text = " Massa Atômica", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 95) ed = Entry(alt) ed.place(x = 58, y = 125) ok = Button(alt, width = 5, text = "OK") ok.place(x = 58, y = 150) fechar = Button(alt, width = 6, text = "Fechar", command = alt.destroy) fechar.place(x = 138, y = 150)
#----------------Função que procura por um elemento def busca() : nome = ed.get() if len(nome) > 0: arquivo = open('dados.txt', 'r') texto = arquivo.readlines() for linha in texto : lista = linha.split() flag = False cont = 0 for x in lista : if cont == 3 : break if x == nome : flag = True break cont += 1 if flag == True : show(lista) break else : jan = Tk() jan.title("Elemento não encontrado") jan["bg"] = "lightyellow" jan.geometry("350x200+600+250") arquivo.close() Label(jan, text = "Deseja criar o elemento " + nome, font = ("Arial", 13, "bold"), bg = jan["bg"]).place(x = 50, y = 35) ans1 = Button(jan, width = 5, text = "SIM", command = create).place(x = 130, y = 75) ans2 = Button(jan, width = 5, text = "NAO", command = jan.destroy).place(x = 130, y = 105) jan.mainloop() jan.destroy() arquivo.close()
ok["command"] = busca alt.mainloop() alt.destroy()
- ----------------Atualiza um elemento
def update() : alt = Tk() alt.title("Atualizar") alt["bg"] = "lightyellow" alt.geometry("300x200+600+250") Label(alt, text = "A pesquisa pode ser realizada por:", font = ("Arial", 11, "bold"), bg = alt["bg"]).place(x = 25, y = 15) Label(alt, text = " Nome", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 35) Label(alt, text = " Símbolo", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 55) Label(alt, text = " N° Atômico", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 75) Label(alt, text = " Massa Atômica", font = ("Arial", 10, "bold"), bg = alt["bg"]).place(x = 0, y = 95) ed = Entry(alt) ed.place(x = 58, y = 125) ok = Button(alt, width = 6, text = "OK") ok.place(x = 58, y = 150) fechar = Button(alt, width = 6, text = "Fechar", command = alt.destroy) fechar.place(x = 138, y = 150) aux = ""
#----------------Função que procura por um elemento para o atualizar def muda(): nome = ed.get() if len(nome) > 0 : arquivo = open('dados.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('dados.txt', 'a') flag = False for linha in texto : lista = linha.split() flag1 = False cont = 0 for x in lista : if cont == 3 : break if x == nome : flag = flag1 = True break cont += 1 if flag1 == True : aux = lista[0] + " " + lista[1] + " " + lista[2] + " " + lista[3] + "\n" show(lista) lista = read() arquivo.writelines(lista) cont += 1 if flag == False : jan = Tk() jan.title("Elemento não encontrado") jan["bg"] = "lightyellow" jan.geometry("350x200+600+250") arquivo.close() Label(jan, text = "Deseja criar o elemento " + nome, font = ("Arial", 13, "bold"), bg = jan["bg"]).place(x = 50, y = 35) ans1 = Button(jan, width = 5, text = "SIM", command = create).place(x = 130, y = 75) ans2 = Button(jan, width = 5, text = "NAO", command = jan.destroy).place(x = 130, y = 105) jan.mainloop() jan.destroy()
arquivo = open('dados.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('dados.txt', 'w') for i in texto: if aux != i : arquivo.writelines(i) arquivo.close()
ok["command"] = muda alt.mainloop() alt.destroy()
- ----------------Deleta um elemento
def delete() : jan = Tk() jan.title("Deletar") jan["bg"] = "lightyellow" jan.geometry("300x200+600+250") lb = Label(jan, text = "Digite o nome do elemento:", font = ("Arial", 13, "bold"), bg = jan["bg"]) bt = Button(jan, width = 6, text = "OK") fecha = Button(jan, width = 6, text = "Fechar", command = jan.destroy) ed = Entry(jan)
#----------------Função que procura por um elemento para o excluir def excluir(): nome = ed.get() if len(nome) > 0 : arquivo = open('dados.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('dados.txt', 'w') cont = 0 flag = False deleted = [] for linha in texto : lista = linha.split() flag1 = False cont = 0 for x in lista : if cont == 3 : break if x == nome : flag = flag1 = True break cont += 1 if flag1 == False : arquivo.writelines(linha) else : deleted = lista cont += 1 if flag == True : alt = Tk() alt.title("Deletar") alt["bg"] = "lightyellow" alt.geometry("350x220+600+250") Label(alt, text = "O elemento " + deleted[0] + " foi deletado.", font = ("Arial", 13, "bold"), bg = alt["bg"]).place(x = 30, y = 70) else : jan = Tk() jan.title("Elemento não encontrado") jan["bg"] = "lightyellow" jan.geometry("350x200+600+250") arquivo.close() Label(jan, text = "Deseja criar o elemento " + nome, font = ("Arial", 13, "bold"), bg = jan["bg"]).place(x = 50, y = 35) ans1 = Button(jan, width = 5, text = "SIM", command = create).place(x = 130, y = 75) ans2 = Button(jan, width = 5, text = "NAO", command = jan.destroy).place(x = 130, y = 105) jan.mainloop() jan.destroy()
lb.place(x = 30, y = 55) ed.place(x = 69, y = 85) bt.place(x = 75, y = 110) fecha.place(x = 155, y = 110) bt["command"] = excluir jan.mainloop() jan.destroy()
- -----------------Janela principal
root = Tk() root.title("Alchemy") root["bg"] = "lightblue" root.geometry("500x500+500+150") Label(root, text = "O que você deseja fazer?", font = ("Arial", 15, "bold"), bg = root["bg"]).place(x = 135, y = 40) criar = Button(root, text = "Criar", width = 7, command = create).place(x = 215, y = 100) atualizar = Button(root, text = "Atualizar", width = 7, command = update).place(x = 215, y = 130) deletar = Button(root, text = "Deletar", width = 7, command = delete).place(x = 215, y = 160) consultar = Button(root, text = "Consultar", width = 7, command = recover).place(x = 215, y = 190) fechar = Button(root, text = "Fechar", width = 7, command = quit).place(x = 215, y = 220) root.mainloop() root.destroy() </syntaxhighlight>
18/06/2017
<syntaxhighlight lang="py" line="1"> from tkinter import * from functools import partial
dicio = {"Nome" : 0, "Símbolo" : 1, "Número Atômico" : 2, "Número de Massa" : 3, 0 : "Nome", 1 : "Símbolo", 2 : "Número Atômico", 3 : "Número de Massa"}
def read() : lista = [] for i in range(4) : if i < 3 : lista.append(input(dicio[i] + ": ") + ' ') else : lista.append(input(dicio[i] + ": ") + '\n') return lista
def show(elemento) : jan = Tk() jan.title(elemento[0]) jan["bg"] = "lightgreen" jan.geometry("300x200+600+250") for i in range(4) : #print(dicio[i] + ": " + elemento[i]) Label(jan, text = dicio[i] + ": " + elemento[i], bg = jan["bg"], font = ("Arial", 14)).pack() bt = Button(jan, text = "Fechar", command = jan.destroy).pack() #jan.mainloop()
def create() : print("Digite a senha para poder cirar: ") while input() != "querocriar123" : print("Senha incorreta") elemento = read() arquivo = open('dados.txt', 'a') #alterar isso pra 'a' arquivo.writelines(elemento) arquivo.close()
def recover() : #nome = input("Digite o nome do elemento: ") alt = Tk() alt.title("Consultar") alt["bg"] = "lightyellow" alt.geometry("300x200+600+250") ed = Entry(alt) ed.place(x = 75, y = 75) ok = Button(alt, width = 5, text = "OK") ok.place(x = 75, y = 100) def busca() : nome = ed.get() arquivo = open('dados.txt', 'r') texto = arquivo.readlines(); for linha in texto : lista = linha.split() flag = False cont = 0; for x in lista : if cont == 3 : break if x == nome : flag = True break cont += 1 if flag == True : show(lista) break else : print("Elemento não encontrado") ans = input("Deseja criar esse elemento? ") if ans == "sim" : arquivo.close() create() arquivo.close() ok["command"] = busca #alt.mainloop();
def update() : #nome = input("Digite o nome do elemento: ") alt = Tk() alt.title("Atualizar") alt["bg"] = "lightyellow" alt.geometry("300x200+600+250") ed = Entry(alt) ed.place(x = 75, y = 75) ok = Button(alt, width = 5, text = "OK") ok.place(x = 75, y = 100) def muda () : nome = ed.get() arquivo = open('dados.txt', 'r') texto = arquivo.readlines(); arquivo.close() arquivo = open('dados.txt', 'w') flag = False for linha in texto : lista = linha.split() flag1 = False cont = 0 for x in lista : if cont == 3 : break if x == nome : flag = flag1 = True break cont += 1 if flag1 == True : show(lista) print("Informe as novas informações") lista = read() arquivo.writelines(lista) else : arquivo.writelines(linha) cont += 1 if flag == False : print("Elemento não encontrado") ans = input("Deseja criar esse elemento? ") if ans == "sim" : arquivo.close() create() ok["command"] = muda #alt.mainloop()
def delete() : nome =input("Digite o nome do elemento: ") arquivo = open('dados.txt', 'r') texto = arquivo.readlines(); arquivo.close() arquivo = open('dados.txt', 'w') cont = 0 flag = False deleted = [] for linha in texto : lista = linha.split() flag1 = False cont = 0 for x in lista : if cont == 3 : break if x == nome : flag = flag1 = True break cont += 1 if flag1 == False : arquivo.writelines(linha) else : deleted = lista cont += 1 if flag == True : print("O elemento " + deleted[0] + " foi deletado.") else : print("Elemento não encontrado")
root = Tk() root.title("Alchemy") root["bg"] = "lightblue"; root.geometry("500x500+500+150") Label(root, text = "O que você deseja fazer?", font = ("Arial", 15, "bold"), bg = root["bg"]).place(x = 135, y = 50) criar = Button(root, text = "Criar", width = 7, command = create).place(x = 215, y = 80) atualizar = Button(root, text = "Atualizar", width = 7, command = update).place(x = 215, y = 110) deletar = Button(root, text = "Deletar", width = 7, command = delete).place(x = 215, y = 140) consultar = Button(root, text = "Consultar", width = 7, command = recover).place(x = 215, y = 170) fechar = Button(root, text = "Fechar", width = 7, command = quit).place(x = 215, y = 200)
root.mainloop() """ acao = input("O que deseja fazer? ") while (acao != "Parar") : if acao == "criar" : create() elif acao == "atualizar" : update(input("Dê uma característica única do elemento que deseja atualizar: ")) elif acao == "deletar" : delete(input("Dê uma característica única do elemento que deseja deletar: ")) else : nome = input("Dê uma característica única do elemento o qual deseja conhecer: ") recover(nome) acao = input("O que deseja fazer? ") """ </syntaxhighlight>16/06/2017<syntaxhighlight lang="py" line="1"> from tkinter import *
dicio = {"Nome" : 0, "Símbolo" : 1, "Número Atômico" : 2, "Número de Massa" : 3, 0 : "Nome", 1 : "Símbolo", 2 : "Número Atômico", 3 : "Número de Massa"}
def read() : lista = [] for i in range(4) : if i < 3 : lista.append(input(dicio[i] + ": ") + ' ') else : lista.append(input(dicio[i] + ": ") + '\n') return lista
def show(elemento) : jan = Tk() jan.title(elemento[0]) jan["bg"] = "lightgreen" jan.geometry("300x200+500+250") for i in range(4) : #print(dicio[i] + ": " + elemento[i]) Label(jan, text = dicio[i] + ": " + elemento[i], bg = jan["bg"], font = ("Arial", 14)).pack() bt = Button(jan, text = "Fechar", command = jan.destroy).pack() jan.mainloop()
def create() : print("Digite a senha para poder cirar: ") while input() != "querocriar123" : print("Senha incorreta") elemento = read() arquivo = open('dados.txt', 'a') #alterar isso pra 'a' arquivo.writelines(elemento) arquivo.close()
def recover(nome) : arquivo = open('dados.txt', 'r') texto = arquivo.readlines(); for linha in texto : lista = linha.split() flag = False cont = 0; for x in lista : if cont == 3 : break if x == nome : flag = True break cont += 1 if flag == True : show(lista) break else : print("Elemento não encontrado") ans = input("Deseja criar esse elemento? ") if ans == "sim" : arquivo.close() create() arquivo.close()
def update(nome) : arquivo = open('dados.txt', 'r') texto = arquivo.readlines(); arquivo.close() arquivo = open('dados.txt', 'w') flag = False for linha in texto : lista = linha.split() flag1 = False cont = 0 for x in lista : if cont == 3 : break if x == nome : flag = flag1 = True break cont += 1 if flag1 == True : print("Esta é a atual descrição do elemento que você deseja atualizar:") show(lista) print("Informe as novas informações") lista = read() arquivo.writelines(lista) else : arquivo.writelines(linha) cont += 1 if flag == False : print("Elemento não encontrado") ans = input("Deseja criar esse elemento? ") if ans == "sim" : arquivo.close() create()
def delete(nome) : arquivo = open('dados.txt', 'r') texto = arquivo.readlines(); arquivo.close() arquivo = open('dados.txt', 'w') cont = 0 flag = False deleted = [] for linha in texto : lista = linha.split() flag1 = False cont = 0 for x in lista : if cont == 3 : break if x == nome : flag = flag1 = True break cont += 1 if flag1 == False: arquivo.writelines(linha) else : deleted = lista cont += 1 print("O elemento " + deleted[0] + " foi deletado.")
acao = input("O que deseja fazer? ") while (acao != "Parar") : if acao == "criar" : create() elif acao == "atualizar" : update(input("Dê uma característica única do elemento que deseja atualizar: ")) elif acao == "deletar" : delete(input("Dê uma característica única do elemento que deseja deletar: ")) else : nome = input("Dê uma característica única do elemento o qual deseja conhecer: ") recover(nome) acao = input("O que deseja fazer? ") </syntaxhighlight>17/06/2017<syntaxhighlight line="1" lang="py"> from tkinter import * from functools import partial
dicio = {"Nome" : 0, "Símbolo" : 1, "Número Atômico" : 2, "Número de Massa" : 3, 0 : "Nome", 1 : "Símbolo", 2 : "Número Atômico", 3 : "Número de Massa"}
def read() : lista = [] for i in range(4) : if i < 3 : lista.append(input(dicio[i] + ": ") + ' ') else : lista.append(input(dicio[i] + ": ") + '\n') return lista
def ler(ed) : nome = ed.get()
def show(elemento) : jan = Tk() jan.title(elemento[0]) jan["bg"] = "lightgreen" jan.geometry("300x200+500+250") for i in range(4) : #print(dicio[i] + ": " + elemento[i]) Label(jan, text = dicio[i] + ": " + elemento[i], bg = jan["bg"], font = ("Arial", 14)).pack() bt = Button(jan, text = "Fechar", command = jan.destroy).pack() jan.mainloop()
def create() : print("Digite a senha para poder cirar: ") while input() != "querocriar123" : print("Senha incorreta") elemento = read() arquivo = open('dados.txt', 'a') #alterar isso pra 'a' arquivo.writelines(elemento) arquivo.close()
def recover() : nome = input("Digite o nome do elemento: ") """ alt = Tk() alt.title("Consultar") alt["bg"] = "lightgrey" alt.geometry("300x200+600+250") ed = Entry(alt) ed.place(x = 75, y = 75) ok = Button(alt, text = "OK", width = 5, command = ler).place(x = 75, y = 100) ok["command"] = partial(ler, ed) """ arquivo = open('dados.txt', 'r') texto = arquivo.readlines(); for linha in texto : lista = linha.split() flag = False cont = 0; for x in lista : if cont == 3 : break if x == nome : flag = True break cont += 1 if flag == True : show(lista) break else : print("Elemento não encontrado") ans = input("Deseja criar esse elemento? ") if ans == "sim" : arquivo.close() create() arquivo.close() alt.mainloop()
def update() : nome = input("Digite o nome do elemento: ") arquivo = open('dados.txt', 'r') texto = arquivo.readlines(); arquivo.close() arquivo = open('dados.txt', 'w') flag = False for linha in texto : lista = linha.split() flag1 = False cont = 0 for x in lista : if cont == 3 : break if x == nome : flag = flag1 = True break cont += 1 if flag1 == True : print("Esta é a atual descrição do elemento que você deseja atualizar:") show(lista) print("Informe as novas informações") lista = read() arquivo.writelines(lista) else : arquivo.writelines(linha) cont += 1 if flag == False : print("Elemento não encontrado") ans = input("Deseja criar esse elemento? ") if ans == "sim" : arquivo.close() create()
def delete() : nome =input("Digite o nome do elemento: ") arquivo = open('dados.txt', 'r') texto = arquivo.readlines(); arquivo.close() arquivo = open('dados.txt', 'w') cont = 0 flag = False deleted = [] for linha in texto : lista = linha.split() flag1 = False cont = 0 for x in lista : if cont == 3 : break if x == nome : flag = flag1 = True break cont += 1 if flag1 == False: arquivo.writelines(linha) else : deleted = lista cont += 1 print("O elemento " + deleted[0] + " foi deletado.")
root = Tk() root.title("Alchemy") root["bg"] = "lightblue"; root.geometry("500x500+500+150") Label(root, text = "O que você deseja fazer?", font = ("Arial", 15, "bold"), bg = root["bg"]).place(x = 135, y = 50) criar = Button(root, text = "Criar", width = 7, command = create).place(x = 215, y = 80) atualizar = Button(root, text = "Atualizar", width = 7, command = update).place(x = 215, y = 110) deletar = Button(root, text = "Deletar", width = 7, command = delete).place(x = 215, y = 140) consultar = Button(root, text = "Consultar", width = 7, command = recover).place(x = 215, y = 170) fechar = Button(root, text = "Fechar", width = 7, command = quit).place(x = 215, y = 200)
root.mainloop() """ acao = input("O que deseja fazer? ") while (acao != "Parar") : if acao == "criar" : create() elif acao == "atualizar" : update(input("Dê uma característica única do elemento que deseja atualizar: ")) elif acao == "deletar" : delete(input("Dê uma característica única do elemento que deseja deletar: ")) else : nome = input("Dê uma característica única do elemento o qual deseja conhecer: ") recover(nome) acao = input("O que deseja fazer? ") """ </syntaxhighlight>