Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- # script que implementa un formulario
- import tkinter as tk
- from tkinter import ttk
- from pprint import pprint
- """
- personas = [
- {"nombre":"Juan", "email":"juan@juan", "tel":"(011)122121", "nac":"argentino"},
- {"nombre":"Ana", "email":"juan@juan", "tel":"(011)122121", "nac":"peruana"},
- ]
- """
- personas = []
- def guardar_datos():
- global personas
- nombre = caja_nombre.get()
- email = caja_email.get()
- nac = caja_nac.get()
- tel = caja_tel.get()
- persona = {"nombre":nombre, "email":email, "tel":tel, "nac":nac}
- personas.append(persona)
- pprint(personas)
- caja_nombre.delete(0, tk.END)
- caja_email.delete(0, tk.END)
- caja_nac.delete(0, tk.END)
- caja_tel.delete(0, tk.END)
- ventana = tk.Tk()
- ventana.title("FORMULARIO")
- ventana.config(width=300, height=400)
- # si quisiera tamaño fijo:
- ventana.resizable(0,0)
- ##### campos del formulario ##########
- # campo nombre
- caja_nombre = ttk.Entry()
- caja_nombre.place(x=100, y=30, width=150, height=25)
- etiqueta = ttk.Label(text="Nombre")
- etiqueta.place(x=10, y=30)
- # campo email
- caja_email = ttk.Entry()
- caja_email.place(x=100, y=80, width=150, height=25)
- etiqueta = ttk.Label(text="Email")
- etiqueta.place(x=10, y=80)
- # campo nacionalidad
- caja_nac = ttk.Entry()
- caja_nac.place(x=100, y=130, width=150, height=25)
- etiqueta = ttk.Label(text="Nacionalidad")
- etiqueta.place(x=10, y=130)
- # campo telefono
- caja_tel = ttk.Entry()
- caja_tel.place(x=100, y=180, width=150, height=25)
- etiqueta = ttk.Label(text="Teléfono")
- etiqueta.place(x=10, y=180)
- ###################################################
- #### botón para guardar datos
- boton = ttk.Button(text="GUARDAR", command=guardar_datos)
- boton.place(x=120, y=250, width=100, height=50)
- ventana.mainloop()
Advertisement
RAW Paste Data
Copied
Advertisement