Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- import tkinter as tk
- from pprint import pprint # imprime listas anidadas con diccionarios y viceversa
- """
- Estructura de datos:
- personas = [
- {"nombre": "Juan", "tel":"01115258", "email":"juan@gmail.com"},
- {"nombre": "Ana", "tel":"0111558755", "email":"anita@gmail.com"},
- {"nombre": "Emilse", "tel":"0114444", "email":"emi@gmail.com"},
- ]
- """
- personas = []
- def guardar():
- global personas
- nombre = caja_nombre.get()
- tel = caja_tel.get()
- email = caja_email.get()
- persona = {"nombre":nombre, "tel":tel, "email": email}
- personas.append(persona)
- # imprimo todas las personas
- pprint(personas)
- # borro el formulario
- caja_email.delete(0,tk.END)
- caja_nombre.delete(0,tk.END)
- caja_tel.delete(0,tk.END)
- ventana = tk.Tk()
- ventana.config(width=300, height=300)
- ventana.resizable(0, 0) # evita redimensionar la ventana
- ventana.title("Formulario")
- # campo nombre
- etiqueta = tk.Label(text="Nombre")
- etiqueta.place(x=20, y=20)
- caja_nombre = tk.Entry()
- caja_nombre.place(x=100, y=20, width=170, height=25)
- # campo telefono
- etiqueta = tk.Label(text="Teléfono")
- etiqueta.place(x=20, y=70)
- caja_tel = tk.Entry()
- caja_tel.place(x=100, y=70, width=170, height=25)
- # campo mail
- etiqueta = tk.Label(text="Email")
- etiqueta.place(x=20, y=120)
- caja_email = tk.Entry()
- caja_email.place(x=100, y=120, width=170, height=25)
- # boton
- boton = tk.Button(text="Guardar", command=guardar)
- boton.place(x=90, y=200, width=120, height=50)
- ventana.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement