Advertisement
teslariu

forms

Nov 6th, 2021
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.58 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # place
  5.  
  6. import tkinter as tk
  7. from tkinter import ttk
  8.  
  9.  
  10. def guardar():
  11.     global personas
  12.     nombre = caja_nombre.get()
  13.     email = caja_email.get()
  14.     tel = caja_tel.get()
  15.     persona = {"nombre":nombre, "email":email, "tel":tel}
  16.     personas.append(persona)
  17.    
  18.     # imprimo los datos
  19.     for persona in personas:
  20.         print(persona)
  21.        
  22.     # borro el formulario
  23.     caja_nombre.delete(0,tk.END)
  24.     caja_email.delete(0,tk.END)
  25.     caja_tel.delete(0,tk.END)
  26.  
  27.  
  28.  
  29.  
  30. """
  31. personas = [
  32.     {"nombre": "Ale", "email":"ale@ale.com", "tel":45646554},
  33.     {"nombre": "Juan", "email":"ad@ale.com", "tel":45646554},
  34.     {"nombre": "Oscar", "email":"dsafdf@ale.com", "tel":898846554},
  35.     {"nombre": "Ana", "email":"dsfdsf@ale.com", "tel":45646554},
  36. ]
  37. """
  38. personas = []
  39.  
  40. ventana = tk.Tk()
  41. ventana.title("Posicionamiento place")
  42. ventana.config(width=400, height=800)
  43. # ventana.resizable(0,0) impide modificar el tamaño de la ventana
  44.  
  45. #### campos de un formulario ###################
  46.  
  47. ## nombre
  48. etiqueta = ttk.Label(text="Nombre")
  49. etiqueta.place(x=20, y=20)
  50. caja_nombre = ttk.Entry()
  51. caja_nombre.place(x=100, y=20, width=200, height=25)
  52.  
  53. ## email
  54. etiqueta = ttk.Label(text="email")
  55. etiqueta.place(x=20, y=70)
  56. caja_email = ttk.Entry()
  57. caja_email.place(x=100, y=70, width=200, height=25)
  58.  
  59. ## tel
  60. etiqueta = ttk.Label(text="Teléfono")
  61. etiqueta.place(x=20, y=120)
  62. caja_tel = ttk.Entry()
  63. caja_tel.place(x=100, y=120, width=200, height=25)
  64.  
  65. ## boton
  66. boton = ttk.Button(text="Guardar", command=guardar)
  67. boton.place(x=150, y=170, width=100, height=40)
  68.  
  69.  
  70. ventana.mainloop()
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement