Advertisement
teslariu

form 2

Oct 24th, 2022
992
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.69 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. """
  5. Formulario de ingreso de datos
  6. """
  7. import tkinter as tk
  8.  
  9. personas = []
  10.  
  11. def leer_formulario():
  12.     global personas
  13.     persona = {
  14.         "nombre":caja_nombre.get(),
  15.         "edad":caja_edad.get(),
  16.         "nac":caja_nac.get(),
  17.         "email":caja_email.get()
  18.     }
  19.     personas.append(persona)
  20.  
  21.  
  22. def borrar_formulario():
  23.     caja_nombre.delete(0,tk.END)
  24.     caja_edad.delete(0,tk.END)
  25.     caja_nac.delete(0,tk.END)
  26.     caja_email.delete(0,tk.END)
  27.    
  28.    
  29. def mostrar_datos():
  30.     import pprint
  31.     global personas
  32.     print()
  33.     pprint.pprint(personas)
  34.    
  35.  
  36.    
  37.  
  38. def clic():
  39.     leer_formulario()
  40.     mostrar_datos()
  41.     borrar_formulario()
  42.    
  43.  
  44. ventana = tk.Tk()
  45. ventana.config(width=450, height=500)
  46. ventana.title("FORMULARIO")
  47. # prohibo redimensionar la ventana
  48. ventana.resizable(False, False)
  49.  
  50. ### Campo nombre
  51. etiqueta = tk.Label(text="Nombre")
  52. etiqueta.place(x=20, y=10)
  53. caja_nombre = tk.Entry()
  54. caja_nombre.place(x=120, y=10, width=200, height=25)
  55.  
  56. ### Campo edad
  57. etiqueta = tk.Label(text="Edad")
  58. etiqueta.place(x=20, y=70)
  59. caja_edad = tk.Entry()
  60. caja_edad.place(x=120, y=70, width=200, height=25)
  61.  
  62. ### Campo nacionalidad
  63. etiqueta = tk.Label(text="Nacionalidad")
  64. etiqueta.place(x=20, y=130)
  65. caja_nac = tk.Entry()
  66. caja_nac.place(x=120, y=130, width=200, height=25)
  67.  
  68. ### Campo email
  69. etiqueta = tk.Label(text="Email")
  70. etiqueta.place(x=20, y=190)
  71. caja_email = tk.Entry()
  72. caja_email.place(x=120, y=190, width=200, height=25)
  73.  
  74.  
  75. # BOTON
  76. boton = tk.Button(text="GUARDAR", command=clic)
  77. boton.place(x=170, y=400, width=120, height=40)
  78.  
  79.  
  80. ventana.mainloop()
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement