Advertisement
teslariu

formulario tkinter

Dec 3rd, 2022
752
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.59 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import tkinter as tk
  5. from pprint import pprint   # imprime listas anidadas con diccionarios y viceversa
  6.  
  7. """
  8. Estructura de datos:
  9. personas = [
  10.        {"nombre": "Juan", "tel":"01115258", "email":"juan@gmail.com"},
  11.        {"nombre": "Ana", "tel":"0111558755", "email":"anita@gmail.com"},
  12.        {"nombre": "Emilse", "tel":"0114444", "email":"emi@gmail.com"},
  13. ]
  14. """
  15.  
  16. personas = []
  17.  
  18. def guardar():
  19.     global personas
  20.     nombre = caja_nombre.get()
  21.     tel = caja_tel.get()
  22.     email = caja_email.get()
  23.     persona = {"nombre":nombre, "tel":tel, "email": email}
  24.     personas.append(persona)
  25.     # imprimo todas las personas
  26.     pprint(personas)
  27.    
  28.     # borro el formulario
  29.     caja_email.delete(0,tk.END)
  30.     caja_nombre.delete(0,tk.END)
  31.     caja_tel.delete(0,tk.END)
  32.  
  33.  
  34.  
  35. ventana = tk.Tk()
  36. ventana.config(width=300, height=300)
  37. ventana.resizable(0, 0)     # evita redimensionar la ventana
  38. ventana.title("Formulario")
  39.  
  40. # campo nombre
  41. etiqueta = tk.Label(text="Nombre")
  42. etiqueta.place(x=20, y=20)
  43. caja_nombre = tk.Entry()
  44. caja_nombre.place(x=100, y=20, width=170, height=25)
  45.  
  46. # campo telefono
  47. etiqueta = tk.Label(text="Teléfono")
  48. etiqueta.place(x=20, y=70)
  49. caja_tel = tk.Entry()
  50. caja_tel.place(x=100, y=70, width=170, height=25)
  51.  
  52.  
  53. # campo mail
  54. etiqueta = tk.Label(text="Email")
  55. etiqueta.place(x=20, y=120)
  56. caja_email = tk.Entry()
  57. caja_email.place(x=100, y=120, width=170, height=25)
  58.  
  59. # boton
  60. boton = tk.Button(text="Guardar", command=guardar)
  61. boton.place(x=90, y=200, width=120, height=50)
  62.  
  63.  
  64.  
  65. ventana.mainloop()
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement