Advertisement
teslariu

formulario tkinter

Sep 8th, 2022
794
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. # Formulario de ingreso de datos
  5. import tkinter as tk
  6. import time
  7. import pprint
  8.  
  9. def guardar():
  10.     global personas
  11.    
  12.     # leo todas las cajas
  13.     nombre = caja_nombre.get()
  14.     email = caja_email.get()
  15.     nac = caja_nac.get()
  16.     tel = caja_tel.get()        
  17.     persona = {"nombre": nombre, "email":email, "nacionalidad":nac, "telefono":tel}
  18.    
  19.     # guardo los datos en la lista de las personas
  20.     personas.append(persona)
  21.    
  22.     # imprimo los valores
  23.     pprint.pprint(personas)
  24.     print()                
  25.     # borro todos los campos
  26.     caja_nombre.delete(0, tk.END)
  27.     caja_email.delete(0, tk.END)
  28.     caja_nac.delete(0, tk.END)
  29.     caja_tel.delete(0, tk.END)      
  30.    
  31.  
  32. # defino mi estructura de datos: lista de diccionarios
  33. """
  34. personas = [
  35.    {"nombre": "Juan", "email":"sarasa", "nacionalidad":"argentino", "telefono":54556},
  36.    {"nombre": "Juana", "email":"sarasa", "nacionalidad":"argentino", "telefono":54556},
  37.    {"nombre": "Yo", "email":"sarasa", "nacionalidad":"argentino", "telefono":54556},
  38.    ]
  39. """
  40. personas = []
  41.  
  42.  
  43. ventana = tk.Tk()
  44. ventana.config(width=400, height=450)
  45. ventana.title("Formulario")
  46. ventana.minsize(320,400)
  47.  
  48.  
  49.  
  50. # Campo nombre
  51. etiqueta = tk.Label(text="Nombre")
  52. etiqueta.place(x=25, y=25)
  53. caja_nombre = tk.Entry()
  54. caja_nombre.place(x=120, y=25, width=200, height=25)
  55.  
  56. # Campo email
  57. etiqueta = tk.Label(text="Email")
  58. etiqueta.place(x=25, y=75)
  59. caja_email = tk.Entry()
  60. caja_email.place(x=120, y=75, width=200, height=25)
  61.  
  62.  
  63. # Campo nacionalidad
  64. etiqueta = tk.Label(text="Nacionalidad")
  65. etiqueta.place(x=25, y=125)
  66. caja_nac = tk.Entry()
  67. caja_nac.place(x=120, y=125, width=200, height=25)
  68.  
  69. # Campo telefono
  70. etiqueta = tk.Label(text="Teléfono")
  71. etiqueta.place(x=25, y=175)
  72. caja_tel = tk.Entry()
  73. caja_tel.place(x=120, y=175, width=200, height=25)
  74.  
  75. boton = tk.Button(text="Guardar", command=guardar)
  76. boton.place(x=120, y=300, width=100, height=50)
  77.  
  78.  
  79. ventana.mainloop()
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement