Advertisement
teslariu

formulario con tkinter

Jul 15th, 2023 (edited)
1,064
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.00 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. import tkinter as tk
  5. from pprint import pprint
  6. from tkinter import messagebox
  7.  
  8. # estructura de datos
  9. """
  10. personas = [
  11.        {"nombre":"Juan", "dni":122313, "tel":"152-25365"},
  12.        {"nombre":"JuanJose", "dni":13422313, "tel":"152-25365"},
  13.        {"nombre":"Ana", "dni":1452313, "tel":"258844365"},
  14. ]
  15. """
  16.  
  17. personas = []
  18.  
  19.  
  20. def leer_datos():
  21.     global personas
  22.     nombre = caja_nombre.get().strip()   # strip borra espacios vacios delante y detras
  23.     if not nombre or nombre.isspace():
  24.         messagebox.showerror(title="Error en Nombre", message="El nombre no posee caracteres válidos")
  25.         return
  26.     dni = caja_dni.get()
  27.     if not dni.isdecimal() or int(dni) == 0:
  28.         messagebox.showerror(title="Error en DNI", message="Ingrese un nro válido")
  29.         return
  30.    
  31.    
  32.     tel = caja_tel.get()
  33.     persona = {"nombre":nombre, "dni":dni, "tel":tel}
  34.     personas.append(persona)
  35.     print()
  36.     pprint(personas)
  37.     caja_dni.delete(0,tk.END)
  38.     caja_nombre.delete(0,tk.END)
  39.     caja_tel.delete(0,tk.END)
  40.    
  41. # que faltaría
  42. def borrar_formulario():
  43.     pass
  44.    
  45.  
  46. def validar_numero():
  47.     pass
  48.    
  49.  
  50. def validar_texto():
  51.     pass
  52.    
  53. def validar_fecha():
  54.     pass  
  55.  
  56. ventana = tk.Tk()
  57. ventana.config(width=400, height=300)
  58. ventana.title("Formulario")
  59. ventana.resizable(False,False)
  60.  
  61. # campos del formulario
  62. # campo nombre
  63. etiqueta = tk.Label(text="Nombre")
  64. etiqueta.place(x=10, y=10)
  65. caja_nombre = tk.Entry()
  66. caja_nombre.place(x=120, y=10, width=200, height=24)
  67.  
  68. # campo dni
  69. etiqueta = tk.Label(text="DNI")
  70. etiqueta.place(x=10, y=60)
  71. caja_dni = tk.Entry()
  72. caja_dni.place(x=120, y=60, width=200, height=24)
  73.  
  74. # campo telefono
  75. etiqueta = tk.Label(text="Teléfono")
  76. etiqueta.place(x=10, y=110)
  77. caja_tel = tk.Entry()
  78. caja_tel.place(x=120, y=110, width=200, height=24)
  79.  
  80.  
  81. boton = tk.Button(text="Enviar", command=leer_datos)
  82. boton.place(x=150, y=180, width=100, height=45)
  83.  
  84. ventana.mainloop()
  85.  
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement