Sem resumo de edição
Etiqueta: visualeditor
Sem resumo de edição
Etiqueta: visualeditor
Linha 1: Linha 1:
== Fase 1 - Concluída ==
== Fase 1 - Concluída ==
<syntaxhighlight lang="python3" line="1">
<syntaxhighlight lang="python3" line="1">
#24/06/2017 - 14:36
#24/06/2017 - 15:16


from tkinter import *
from tkinter import *
Linha 85: Linha 85:
senha()
senha()
elemento = read()
elemento = read()
arquivo = open('dados.txt', 'r')
aux = elemento[0] + elemento[1] + elemento[2] + elemento[3]
flag = True
if len(aux) > 4:
texto = arquivo.readlines()
arquivo = open('dados.txt', 'r')
arquivo.close()
flag = True
for i in elemento:
texto = arquivo.readlines()
for j in texto:
arquivo.close()
lista = j.split()
for i in elemento:
cont = 0
for j in texto:
for k in lista:
lista = j.split()
if cont < 3:
cont = 0
if i == (k + ' '): flag = False
for k in lista:
if flag == False: break
if cont < 3:
else: break
if i == (k + ' '): flag = False
cont += 1
if flag == False: break
else: break
cont += 1
if flag == False: break
if flag == False: break
if flag == False: break
if flag == False: break
arquivo = open('dados.txt', 'a')
arquivo = open('dados.txt', 'a')
if flag == True:  
if flag == True:  
arquivo.writelines(elemento)
arquivo.writelines(elemento)
else:
else:
jan = Tk()
jan = Tk()
jan.title("Elemento Existente")
jan.title("Elemento Existente")
jan["bg"] = "lightyellow"
jan["bg"] = "lightyellow"
jan.geometry("350x200+600+250")
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)
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)
bt = Button(jan, text = "Fechar", command = jan.quit).place(x = 135, y = 105)
jan.mainloop()
jan.mainloop()
jan.destroy()
jan.destroy()
arquivo.close()
arquivo.close()


#----------------Consulta um elememnto
#----------------Consulta um elememnto
Linha 137: Linha 140:
def busca() :
def busca() :
nome = ed.get()
nome = ed.get()
arquivo = open('dados.txt', 'r')
if len(nome) > 0:
texto = arquivo.readlines()
print("@@")
for linha in texto :
arquivo = open('dados.txt', 'r')
lista = linha.split()
texto = arquivo.readlines()
flag = False
for linha in texto :
cont = 0
lista = linha.split()
for x in lista :
flag = False
if cont == 3 : break
cont = 0
if x == nome :
for x in lista :
flag = True
if cont == 3 : break
if x == nome :
flag = True
break
cont += 1
if flag == True :
show(lista)
break
break
cont += 1
else :
if flag == True :
jan = Tk()
show(lista)
jan.title("Elemento não encontrado")
break
jan["bg"] = "lightyellow"
else :
jan.geometry("350x200+600+250")
jan = Tk()
arquivo.close()
jan.title("Elemento não encontrado")
Label(jan, text = "Deseja criar o elemento " + nome, font = ("Arial", 13, "bold"), bg = jan["bg"]).place(x = 50, y = 35)
jan["bg"] = "lightyellow"
ans1 = Button(jan, width = 5, text = "SIM", command = create).place(x = 130, y = 75)
jan.geometry("350x200+600+250")
ans2 = Button(jan, width = 5, text = "NAO", command = jan.destroy).place(x = 130, y = 105)
jan.mainloop()
jan.destroy()
arquivo.close()
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
ok["command"] = busca
alt.mainloop()
alt.mainloop()
Linha 191: Linha 197:
def muda():
def muda():
nome = ed.get()
nome = ed.get()
arquivo = open('dados.txt', 'r')
if len(nome) > 0 : 
texto = arquivo.readlines()
arquivo = open('dados.txt', 'r')
arquivo.close()
texto = arquivo.readlines()
arquivo = open('dados.txt', 'a')
arquivo.close()
flag = False
arquivo = open('dados.txt', 'a')
for linha in texto :
flag = False
lista = linha.split()
for linha in texto :
flag1 = False
lista = linha.split()
cont = 0
flag1 = False
for x in lista :
cont = 0
if cont == 3 : break
for x in lista :
if x == nome :
if cont == 3 : break
flag = flag1 = True
if x == nome :
break
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
cont += 1
if flag1 == True :
if flag == False :
aux = lista[0] + " " + lista[1] + " " + lista[2] + " " + lista[3] + "\n"
jan = Tk()
show(lista)
jan.title("Elemento não encontrado")
lista = read()
jan["bg"] = "lightyellow"
arquivo.writelines(lista)
jan.geometry("350x200+600+250")
cont += 1
arquivo.close()
if flag == False :
Label(jan, text = "Deseja criar o elemento " + nome, font = ("Arial", 13, "bold"), bg = jan["bg"]).place(x = 50, y = 35)
jan = Tk()
ans1 = Button(jan, width = 5, text = "SIM", command = create).place(x = 130, y = 75)
jan.title("Elemento não encontrado")
ans2 = Button(jan, width = 5, text = "NAO", command = jan.destroy).place(x = 130, y = 105)
jan["bg"] = "lightyellow"
jan.mainloop()
jan.geometry("350x200+600+250")
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()
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
ok["command"] = muda
alt.mainloop()
alt.mainloop()
Linha 251: Linha 259:
def excluir():  
def excluir():  
nome = ed.get()
nome = ed.get()
arquivo = open('dados.txt', 'r')
if len(nome) > 0 :
texto = arquivo.readlines()
arquivo = open('dados.txt', 'r')
arquivo.close()
texto = arquivo.readlines()
arquivo = open('dados.txt', 'w')
arquivo.close()
cont = 0
arquivo = open('dados.txt', 'w')
flag = False
deleted = []
for linha in texto :
lista = linha.split()
flag1 = False
cont = 0
cont = 0
for x in lista :
flag = False
if cont == 3 : break
deleted = []
if x == nome :
for linha in texto :
flag = flag1 = True
lista = linha.split()
break
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
cont += 1
if flag1 == False :
if flag == True :
arquivo.writelines(linha)
alt = Tk()
else : deleted = lista
alt.title("Deletar")
cont += 1
alt["bg"] = "lightyellow"
if flag == True :
alt.geometry("350x220+600+250")
alt = Tk()
Label(alt, text = "O elemento " + deleted[0] + " foi deletado.", font = ("Arial", 13, "bold"), bg = alt["bg"]).place(x = 30, y = 70)
alt.title("Deletar")
else :
alt["bg"] = "lightyellow"
jan = Tk()
alt.geometry("350x220+600+250")
jan.title("Elemento não encontrado")
Label(alt, text = "O elemento " + deleted[0] + " foi deletado.", font = ("Arial", 13, "bold"), bg = alt["bg"]).place(x = 30, y = 70)
jan["bg"] = "lightyellow"
else :
jan.geometry("350x200+600+250")
jan = Tk()
arquivo.close()
jan.title("Elemento não encontrado")
Label(jan, text = "Deseja criar o elemento " + nome, font = ("Arial", 13, "bold"), bg = jan["bg"]).place(x = 50, y = 35)
jan["bg"] = "lightyellow"
ans1 = Button(jan, width = 5, text = "SIM", command = create).place(x = 130, y = 75)
jan.geometry("350x200+600+250")
ans2 = Button(jan, width = 5, text = "NAO", command = jan.destroy).place(x = 130, y = 105)
arquivo.close()
jan.mainloop()
Label(jan, text = "Deseja criar o elemento " + nome, font = ("Arial", 13, "bold"), bg = jan["bg"]).place(x = 50, y = 35)
jan.destroy()
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)
lb.place(x = 30, y = 55)

Edição das 18h16min de 24 de junho de 2017

Fase 1 - Concluída

<syntaxhighlight lang="python3" line="1">

  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"}

  1. ----------------Ler os dados de um elememnto

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

  1. ----------------Mostra um elememnto

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()

  1. ----------------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()


  1. ----------------Adiciona um elememnto

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()


  1. ----------------Consulta um elememnto

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 elememnto def busca() : nome = ed.get() if len(nome) > 0: print("@@") 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()

  1. ----------------Atualiza um elememnto

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 elememnto 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()

  1. ----------------Deleta um elememnto

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 elememnto 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()


  1. -----------------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>