teslariu

form tkinter

Feb 11th, 2023
784
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
  6.  
  7. # personas = [ {"nombre":"Juan", "email":"[email protected]", "tel":34334},
  8. #               {"nombre":"Ana", "email":"[email protected]", "tel":1134334},
  9. #         ]
  10.  
  11. personas = []
  12.  
  13. def guardar_datos():
  14.     persona = {}
  15.     global personas
  16.     nombre = caja_nombre.get()
  17.     email = caja_email.get()
  18.     tel = caja_tel.get()
  19.     persona["nombre"] = nombre
  20.     persona["email"] = email
  21.     persona["tel"] = tel
  22.     personas.append(persona)
  23.     pprint(personas)
  24.     # borro los campos del formulario
  25.     caja_email.delete(0, tk.END)
  26.     caja_nombre.delete(0, tk.END)
  27.     caja_tel.delete(0, tk.END)
  28.  
  29.  
  30.  
  31. ventana = tk.Tk()
  32. ventana.config(width=400, height=300)
  33. ventana.title("Formulario de datos")
  34. # bloqueo el redimensionamiento de la ventana para
  35. # no "desarmar" el formulario
  36. ventana.resizable(0,0)
  37.  
  38. # Los formularios tienen campos de valores
  39. # Campo nombre
  40. etiqueta = tk.Label(text="Nombre")
  41. etiqueta.place(x=10, y=10)
  42. caja_nombre = tk.Entry()
  43. caja_nombre.place(x=100, y=10, width=200, height=25)
  44.  
  45. # Campo email
  46. etiqueta = tk.Label(text="Email")
  47. etiqueta.place(x=10, y=60)
  48. caja_email = tk.Entry()
  49. caja_email.place(x=100, y=60, width=200, height=25)
  50.  
  51. # Campo telefono
  52. etiqueta = tk.Label(text="Telefono")
  53. etiqueta.place(x=10, y=110)
  54. caja_tel = tk.Entry()
  55. caja_tel.place(x=100, y=110, width=200, height=25)
  56.  
  57. # Boton para ingresar datos
  58. boton = tk.Button(text="Guardar", command=guardar_datos)
  59. boton.place(x=130, y=180, width=100, height=50)
  60.  
  61. ventana.mainloop()
  62.  
  63.  
  64.  
  65.    
  66.    
  67.  
Advertisement
Add Comment
Please, Sign In to add comment