Created
December 14, 2012 16:10
-
-
Save anonymous/4286566 to your computer and use it in GitHub Desktop.
Script de exemplo, usando o Tkinter para salvar dados em um arquivo de texto.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
from Tkinter import * | |
def salvar_dados(): | |
with open('dados.txt', 'a') as dados: | |
dados.write('Nome: %s\n' % nome.get()) | |
dados.write('Categoria: %s\n' % categoria.get()) | |
dados.write('Endereco:\n%s\n' % endereco.get('1.0', END)) | |
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') | |
custom_msg = StringVar() | |
custom_msg.set('Cadastre os dados de entrega.') | |
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) | |
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