teslariu

formulario tk

Oct 24th, 2022
902
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.67 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. """
  5. Formulario de ingreso de datos
  6. """
  7. import tkinter as tk
  8.  
  9. def leer_formulario():
  10.     nombre = caja_nombre.get()
  11.     edad = caja_edad.get()
  12.     nac = caja_nac.get()
  13.     email = caja_email.get()
  14.  
  15.  
  16. def borrar_formulario():
  17.     caja_nombre.delete(0,tk.END)
  18.     caja_edad.delete(0,tk.END)
  19.     caja_nac.delete(0,tk.END)
  20.     caja_email.delete(0,tk.END)
  21.    
  22.    
  23. def mostrar_datos():
  24.     print(f"""
  25.        nombre: {caja_nombre.get()}
  26.        edad: {caja_edad.get()}
  27.        nacionalidad: {caja_nac.get()}
  28.        email: {caja_email.get()}
  29.    """)
  30.    
  31.  
  32.    
  33.  
  34. def clic():
  35.     leer_formulario()
  36.     mostrar_datos()
  37.     borrar_formulario()
  38.    
  39.  
  40. ventana = tk.Tk()
  41. ventana.config(width=450, height=500)
  42. ventana.title("FORMULARIO")
  43. # prohibo redimensionar la ventana
  44. ventana.resizable(False, False)
  45.  
  46. ### Campo nombre
  47. etiqueta = tk.Label(text="Nombre")
  48. etiqueta.place(x=20, y=10)
  49. caja_nombre = tk.Entry()
  50. caja_nombre.place(x=120, y=10, width=200, height=25)
  51.  
  52. ### Campo edad
  53. etiqueta = tk.Label(text="Edad")
  54. etiqueta.place(x=20, y=70)
  55. caja_edad = tk.Entry()
  56. caja_edad.place(x=120, y=70, width=200, height=25)
  57.  
  58. ### Campo nacionalidad
  59. etiqueta = tk.Label(text="Nacionalidad")
  60. etiqueta.place(x=20, y=130)
  61. caja_nac = tk.Entry()
  62. caja_nac.place(x=120, y=130, width=200, height=25)
  63.  
  64. ### Campo email
  65. etiqueta = tk.Label(text="Email")
  66. etiqueta.place(x=20, y=190)
  67. caja_email = tk.Entry()
  68. caja_email.place(x=120, y=190, width=200, height=25)
  69.  
  70.  
  71. # BOTON
  72. boton = tk.Button(text="GUARDAR", command=clic)
  73. boton.place(x=170, y=400, width=120, height=40)
  74.  
  75.  
  76. ventana.mainloop()
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
Advertisement
Add Comment
Please, Sign In to add comment