Skip to content

Instantly share code, notes, and snippets.

@macndesign
Created December 16, 2012 00:57
Show Gist options
  • Save macndesign/4301705 to your computer and use it in GitHub Desktop.
Save macndesign/4301705 to your computer and use it in GitHub Desktop.
Teste com tkinter e Python 3.3
from tkinter import *
def salvar_dados():
valor_nome = nome.get()
valor_categoria = categoria.get()
valor_endereco = endereco.get('1.0', END)
with open('dados.txt', mode='a', encoding='utf8') as dados:
dados.write("""
Nome: {}
Categoria: {}
Endereço: {}
""".format(valor_nome, valor_categoria, valor_endereco))
nome.delete(0, END)
categoria.delete(0, END)
endereco.delete('1.0', END)
nome.focus()
custom_msg.set('Dados salvos com sucesso!')
app = Tk()
app.title('Cadastro de entregas')
msg_padrao = 'Cadastre os dados de entrega.'
custom_msg = StringVar()
custom_msg.set(msg_padrao)
msg = Label(app, textvariable=custom_msg)
msg.pack(padx=10, pady=10)
Label(app, text='Nome').pack(padx=10)
nome = Entry(app)
nome.pack(padx=10, pady=10)
nome.focus_set()
def key_nome(e):
custom_msg.set('{} ({})'.format(msg_padrao, len(nome.get())))
nome.bind('<Key>', key_nome)
Label(app, text='Categoria').pack(padx=10)
categoria = Entry(app)
categoria.pack(padx=10, pady=10)
Label(app, text=u'Endereço').pack(padx=10)
endereco = Text(app)
endereco.pack(padx=10, pady=10)
salvar = Button(app, text='Salvar', command=salvar_dados)
salvar.pack(padx=10, pady=10)
app.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment