Advertisement
teslariu

form

Dec 16th, 2021
946
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.11 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Formulario de ingreso de datos
  4.  
  5. import tkinter as tk
  6. import pprint
  7.  
  8. # Estructura de datos:
  9. # personas = [
  10. #       {"nombre":"Juan", "email":"ake@ali.com", "tel":1213323, "nac":"Argentino"},
  11. #       {"nombre":"Ana", "email":"acscke@ali.com", "tel":12223, "nac":"Uruguayo"},
  12. #       {"nombre":"Tito", "email":"akcxve@ali.com", "tel":125513323, "nac":"Argentino"},
  13. #   ]
  14.  
  15.  
  16. def guardar_datos():
  17.     global personas
  18.     # leo el contenido de las cajas
  19.     nombre = caja_nombre.get()
  20.     email = caja_email.get()
  21.     tel = caja_tel.get()
  22.     nac = caja_nac.get()
  23.    
  24.     # creo la persona
  25.     persona = {
  26.             "nombre":nombre,
  27.             "email":email,
  28.             "tel":tel,
  29.             "nac":nac,
  30.         }
  31.    
  32.     # agrego la persona a la lista
  33.     personas.append(persona)
  34.    
  35.     # imprimo todos los datos
  36.     pprint.pprint(personas)
  37.    
  38.     # borro las cajas
  39.     caja_email.delete(0, tk.END)
  40.     caja_tel.delete(0, tk.END)
  41.     caja_nac.delete(0, tk.END)
  42.     caja_nombre.delete(0, tk.END)
  43.    
  44. ###### programa principal  ####################### 
  45.  
  46. personas = []
  47. ventana = tk.Tk()
  48. ventana.title("Formulario de inscripción")
  49. ventana.config(width=400, height=300, bg="dark sea green")
  50.  
  51. # Impido que se modifique el tamaño de la ventana
  52. ventana.resizable(0,0)
  53.  
  54.  
  55. ######   Campo nombre
  56. etiqueta = tk.Label(text="Nombre", bg="dark sea green")
  57. etiqueta.place(x=20, y=20)
  58. caja_nombre = tk.Entry()
  59. caja_nombre.place(x=120, y=20, width=200, height=25)
  60.  
  61. ###### Campo email
  62. etiqueta = tk.Label(text="Email", bg="dark sea green")
  63. etiqueta.place(x=20, y=70)
  64. caja_email = tk.Entry()
  65. caja_email.place(x=120, y=70, width=200, height=25)
  66.  
  67. ######   Campo telefono
  68. etiqueta = tk.Label(text="Teléfono", bg="dark sea green")
  69. etiqueta.place(x=20, y=120)
  70. caja_tel = tk.Entry()
  71. caja_tel.place(x=120, y=120, width=200, height=25)
  72.  
  73. ###### Campo nacionalidad
  74. etiqueta = tk.Label(text="Nacionalidad", bg="dark sea green")
  75. etiqueta.place(x=20, y=170)
  76. caja_nac = tk.Entry()
  77. caja_nac.place(x=120, y=170, width=200, height=25)
  78.  
  79. # Botón
  80. boton = tk.Button(text="Guardar", command=guardar_datos)
  81. boton.place(x=150, y=230, width=100, height=40)
  82.  
  83. ventana.mainloop() 
  84.        
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement