teslariu

form

Jun 13th, 2022
1,388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.49 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import tkinter as tk
  5.  
  6. def guardar():
  7.     #datos: una lista de diccionarios
  8.     # leo los datos y armo un diccionario
  9.     # voy a usar una biblioteca especial para impresion
  10.     import pprint
  11.    
  12.     global personas # accedo a la lista externa a la función
  13.    
  14.     nombre = caja_nombre.get()
  15.     email = caja_email.get()
  16.     telefono = caja_tel.get()
  17.     persona = {"nombre":nombre, "email":email, "telefono":telefono}
  18.     personas.append(persona)
  19.     pprint.pprint(personas)
  20.    
  21.     # borro el formulario
  22.     caja_nombre.delete(0,tk.END)
  23.     caja_email.delete(0,tk.END)
  24.     caja_tel.delete(0,tk.END)
  25.  
  26.  
  27.  
  28.  
  29.  
  30. #creo una lista vacia para guardar los datos    
  31. personas = []
  32.  
  33. ventana = tk.Tk()
  34. ventana.config(width=400, height=300)
  35. ventana.title("Formulario")
  36.  
  37. # si quiero el tamaño fijo
  38. # ventana.resizable(0,0)
  39.  
  40. #### campo del nombre
  41. caja_nombre = tk.Entry()
  42. caja_nombre.place(x=150, y=20, width=200, height=25)
  43. etiqueta = tk.Label(text="Nombre")
  44. etiqueta.place(x=30, y=20)
  45.  
  46. #### campo del email
  47. caja_email = tk.Entry()
  48. caja_email.place(x=150, y=70, width=200, height=25)
  49. etiqueta = tk.Label(text="Email")
  50. etiqueta.place(x=30, y=70)
  51.  
  52. #### campo del telefono
  53. caja_tel = tk.Entry()
  54. caja_tel.place(x=150, y=120, width=200, height=25)
  55. etiqueta = tk.Label(text="Teléfono")
  56. etiqueta.place(x=30, y=120)
  57.  
  58.  
  59. boton = tk.Button(text="Guardar", command=guardar)
  60. boton.place(x=150, y=200, width=100, height=50)
  61.  
  62.  
  63. ventana.mainloop()
  64.  
Advertisement
Add Comment
Please, Sign In to add comment