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
- from tkinter import messagebox
- # estructura de datos
- """
- personas = [
- {"nombre":"Juan", "dni":122313, "tel":"152-25365"},
- {"nombre":"JuanJose", "dni":13422313, "tel":"152-25365"},
- {"nombre":"Ana", "dni":1452313, "tel":"258844365"},
- ]
- """
- personas = []
- def leer_datos():
- global personas
- nombre = caja_nombre.get().strip() # strip borra espacios vacios delante y detras
- if not nombre or nombre.isspace():
- messagebox.showerror(title="Error en Nombre", message="El nombre no posee caracteres válidos")
- return
- dni = caja_dni.get()
- if not dni.isdecimal() or int(dni) == 0:
- messagebox.showerror(title="Error en DNI", message="Ingrese un nro válido")
- return
- tel = caja_tel.get()
- persona = {"nombre":nombre, "dni":dni, "tel":tel}
- personas.append(persona)
- print()
- pprint(personas)
- caja_dni.delete(0,tk.END)
- caja_nombre.delete(0,tk.END)
- caja_tel.delete(0,tk.END)
- # que faltaría
- def borrar_formulario():
- pass
- def validar_numero():
- pass
- def validar_texto():
- pass
- def validar_fecha():
- pass
- ventana = tk.Tk()
- ventana.config(width=400, height=300)
- ventana.title("Formulario")
- ventana.resizable(False,False)
- # campos del formulario
- # campo nombre
- etiqueta = tk.Label(text="Nombre")
- etiqueta.place(x=10, y=10)
- caja_nombre = tk.Entry()
- caja_nombre.place(x=120, y=10, width=200, height=24)
- # campo dni
- etiqueta = tk.Label(text="DNI")
- etiqueta.place(x=10, y=60)
- caja_dni = tk.Entry()
- caja_dni.place(x=120, y=60, width=200, height=24)
- # campo telefono
- etiqueta = tk.Label(text="Teléfono")
- etiqueta.place(x=10, y=110)
- caja_tel = tk.Entry()
- caja_tel.place(x=120, y=110, width=200, height=24)
- boton = tk.Button(text="Enviar", command=leer_datos)
- boton.place(x=150, y=180, width=100, height=45)
- ventana.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement