Advertisement
teslariu

formulario

Nov 10th, 2021
599
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.25 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Posicionamiento place
  5.  
  6. import tkinter as tk
  7. from tkinter import ttk
  8.  
  9. # estructura de datos:
  10. # personas =  [
  11. #       {"nombre":"Hugo", "email":"f@er.com", "tel":112123, "nac":"rusa", "dir": "Paso 44"},
  12. #       {"nombre":"Ana", "email":"f@er.com", "tel":112123, "nac":"rusa", "dir": "Paso 44"},
  13. #       {"nombre":"Hernan", "email":"f@er.com", "tel":112123, "nac":"rusa", "dir": "Paso 44"},
  14. #       {"nombre":"Analia", "email":"f@er.com", "tel":112123, "nac":"rusa", "dir": "Paso 44"},
  15. #       ]
  16.  
  17.  
  18.  
  19. def guardar():
  20.     # leo el formulario
  21.     nombre = caja_nombre.get()
  22.     email = caja_email.get()
  23.     direcc = caja_dir.get()
  24.     nac = caja_nac.get()
  25.     tel = caja_tel.get()
  26.     # guardo los datos
  27.     persona = {"nombre":nombre, "email":email, "tel":tel, "nac":nac, "dir":direcc}
  28.     personas.append(persona)
  29.     # imprimo los datos
  30.     print("\nListado")
  31.     print("-------")
  32.     for persona in personas:
  33.         print(persona)
  34.     # borro el formulario
  35.     caja_dir.delete(0,tk.END)
  36.     caja_tel.delete(0,tk.END)
  37.     caja_email.delete(0,tk.END)
  38.     caja_nombre.delete(0,tk.END)
  39.     caja_nac.delete(0,tk.END)
  40.  
  41.  
  42. personas = []
  43.  
  44. ventana = tk.Tk()
  45. ventana.title("FORMULARIO")
  46. ventana.resizable(0,0)   # impide redimensionar la ventana
  47. ventana.config(width=400, height=500)
  48.  
  49. #####3 campos del formulario  ################
  50.  
  51. ## nombre
  52. etiqueta = ttk.Label(text="Nombre")
  53. etiqueta.place(x=20, y=40)
  54. caja_nombre = ttk.Entry()
  55. caja_nombre.place(x=120, y=40, width=200, height=25)
  56.  
  57. ## email
  58. etiqueta = ttk.Label(text="Email")
  59. etiqueta.place(x=20, y=100)
  60. caja_email = ttk.Entry()
  61. caja_email.place(x=120, y=100, width=200, height=25)
  62.  
  63. ## direccion
  64. etiqueta = ttk.Label(text="Dirección")
  65. etiqueta.place(x=20, y=160)
  66. caja_dir = ttk.Entry()
  67. caja_dir.place(x=120, y=160, width=200, height=25)
  68.  
  69. ## nacionalidad
  70. etiqueta = ttk.Label(text="Nacionalidad")
  71. etiqueta.place(x=20, y=220)
  72. caja_nac = ttk.Entry()
  73. caja_nac.place(x=120, y=220, width=200, height=25)
  74.  
  75. ## telefono
  76. etiqueta = ttk.Label(text="Teléfono")
  77. etiqueta.place(x=20, y=280)
  78. caja_tel = ttk.Entry()
  79. caja_tel.place(x=120, y=280, width=200, height=25)
  80.  
  81. ###### boton
  82. boton = tk.Button(text="GUARDAR DATOS", bg="CadetBlue4", command=guardar)
  83. boton.place(x=150, y=350, width=120, height=70)
  84.  
  85.  
  86. ventana.mainloop()
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement