Advertisement
teslariu

form con estilos

Jul 11th, 2023
978
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.96 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4.  
  5. import tkinter as tk
  6. import pprint
  7.  
  8. # defino mi estructura de datos:
  9. # lista = [
  10. #       {"nombre": "Ana"},
  11. #       {"nac": "Argentina"},
  12. #       {"tel": "11-2525-2257"}
  13. # ]
  14. #
  15.  
  16. def guardar_datos():
  17.     global lista
  18.    
  19.     # leo los datos del formulario
  20.     nombre = caja_nombre.get()
  21.     nac = caja_nac.get()
  22.     tel = caja_tel.get()
  23.    
  24.     # creo el diccionario con los datos leídos
  25.     persona = {"nombre":nombre, "nac":nac, "tel":tel}
  26.    
  27.     # agrego el diccionario de datos a la lista
  28.     lista.append(persona)
  29.     pprint.pprint(lista)
  30.    
  31.     # borro el formulario
  32.     caja_nac.delete(0, tk.END)
  33.     caja_nombre.delete(0, tk.END)
  34.     caja_tel.delete(0, tk.END)
  35.    
  36.    
  37.    
  38.  
  39. lista = []
  40.  
  41.  
  42. ventana = tk.Tk()
  43. ventana.config(width=300, height=280, bg="dark slate gray")
  44. ventana.title("Formulario")
  45. ventana.resizable(False,False) # evita redimensionar la ventana
  46.  
  47. # campo nombre
  48. etiqueta = tk.Label(text="Nombre")
  49. etiqueta.place(x=10, y=10)
  50. etiqueta.config(bg="dark slate grey", fg="white", font=("Courier",14))
  51. caja_nombre = tk.Entry()
  52. caja_nombre.config(bg="khaki")
  53. caja_nombre.place(x=100, y=10, width=150, height=24)
  54.  
  55.  
  56. # campo nacionalidad
  57. etiqueta = tk.Label(text="Nacionalidad")
  58. etiqueta.config(bg="dark slate grey", fg="white", font=("Georgia",10))
  59. etiqueta.place(x=10, y=70)
  60. caja_nac = tk.Entry()
  61. caja_nac.config(bg="khaki")
  62. caja_nac.place(x=100, y=70, width=150, height=24)
  63.  
  64.  
  65. # campo telefono
  66. etiqueta = tk.Label(text="Teléfono")
  67. etiqueta.place(x=10, y=130)
  68. etiqueta.config(bg="dark slate grey", fg="white", font=("Helvetica",10))
  69. caja_tel = tk.Entry()
  70. caja_tel.config(bg="khaki")
  71. caja_tel.place(x=100, y=130, width=150, height=24)
  72.  
  73.  
  74. # boton
  75. boton = tk.Button(text="Guardar", command=guardar_datos)
  76. boton.place(x=120, y=200, width=80, height=35)
  77. boton.config(bg="dim grey", fg="white", font=("Helvetica",10))
  78.  
  79. ventana.mainloop()
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement