Foi adicionado ao programa pequenas funcionalidades de interação via interface ao invés de terminal Etiqueta: visualeditor |
mSem resumo de edição Etiqueta: visualeditor |
||
| Linha 1: | Linha 1: | ||
16/06/2017<syntaxhighlight lang="py" line="1"> | 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 * | from tkinter import * | ||
Edição das 11h41min de 18 de junho de 2017
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>