Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- """
- Script que implementa un formulario de ingreso de datos
- """
- import tkinter as tk
- import pprint
- def guardar_datos():
- global personas
- nombre = caja_nombre.get()
- edad = caja_edad.get()
- tel = caja_tel.get()
- email = caja_email.get()
- persona = {"nombre":nombre, "edad":edad, "tel":tel, "email":email}
- personas.append(persona)
- # imprimo los datos
- print()
- pprint.pprint(personas)
- # borro los campos
- caja_nombre.delete(0,tk.END)
- caja_edad.delete(0,tk.END)
- caja_tel.delete(0,tk.END)
- caja_email.delete(0,tk.END)
- # creo una lista para guardar datos. Cada persona serĂ¡ un diccionario:
- personas = []
- ventana = tk.Tk()
- ventana.config(width=600, height=350, bg="cyan4")
- ventana.title("Formulario")
- ventana.resizable(0,0)
- ######## CAMPO NOMBRE #################
- caja_nombre = tk.Entry()
- caja_nombre.place(x=200, y=20, width=200, height=25)
- etiqueta = tk.Label(text="Nombre", bg="cyan4", font=('arial',12,'bold'))
- etiqueta.place(x=50, y=20)
- ######## CAMPO EMAIL #################
- caja_email = tk.Entry()
- caja_email.place(x=200, y=70, width=200, height=25)
- etiqueta = tk.Label(text="Email", bg="cyan4", font=('arial',12,'bold'))
- etiqueta.place(x=50, y=70)
- ######## CAMPO TEL #################
- caja_tel = tk.Entry()
- caja_tel.place(x=200, y=120, width=200, height=25)
- etiqueta = tk.Label(text="Telefono", bg="cyan4", font=('arial',12,'bold'))
- etiqueta.place(x=50, y=120)
- ######## CAMPO EDAD #################
- caja_edad = tk.Entry()
- caja_edad.place(x=200, y=170, width=200, height=25)
- etiqueta = tk.Label(text="Edad", bg="cyan4", font=('arial',12,'bold'))
- etiqueta.place(x=50, y=170)
- # hago un boton
- boton = tk.Button(text="Guardar", command=guardar_datos)
- boton.place(x=200, y=250, width=100, height=30)
- ventana.mainloop()
Advertisement
RAW Paste Data
Copied
Advertisement