Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- # formulario
- # posicionamiento place
- import tkinter as tk
- from tkinter import ttk
- from tkinter import messagebox
- '''estructura de datos
- alumnos = [
- {"nombre": "Juan", "email":"juan@gmail.com", "tel":"456454", "curso":"Python"},
- {"nombre": "JuanJose", "email":"juaao@gmail.com", "tel":"45677454", "curso":"C"}
- ]
- '''
- def leer_datos():
- global alumnos
- # verifico que acepte las condiciones
- valor = estado_casilla.get()
- if not valor:
- messagebox.showinfo(title="Términos y condiciones", message="Debe aceptar")
- return
- nombre = caja_nombre.get()
- if nombre.isspace() or not nombre:
- messagebox.showerror(title="Error en nombre", message="Nombre inválido")
- return
- email = caja_email.get()
- if "@" not in email:
- messagebox.showerror(title="Error en email", message="Dirección inválida")
- return
- tel = caja_tel.get()
- curso = lista_cursos.get()
- alumno = {"nombre": nombre, "email":email, "tel":tel, "curso":curso}
- alumnos.append(alumno)
- def borrar_formulario():
- caja_nombre.delete(0, tk.END)
- caja_tel.delete(0, tk.END)
- caja_email.delete(0, tk.END)
- def guardar_datos():
- from pprint import pprint
- global alumnos
- leer_datos()
- pprint(alumnos)
- borrar_formulario()
- alumnos = []
- ventana = tk.Tk()
- ventana.title("Formulario de inscripción")
- ventana.config(width=400, height=370)
- ventana.resizable(False,False)
- # campo nombre
- etiqueta = ttk.Label(text="Nombre")
- etiqueta.place(x=10, y=10)
- caja_nombre = ttk.Entry()
- caja_nombre.place(x=130, y=10, width=180, height=25)
- # campo email
- etiqueta = ttk.Label(text="Email")
- etiqueta.place(x=10, y=60)
- caja_email = ttk.Entry()
- caja_email.place(x=130, y=60, width=180, height=25)
- # campo telefono
- etiqueta = ttk.Label(text="Teléfono")
- etiqueta.place(x=10, y=110)
- caja_tel = ttk.Entry()
- caja_tel.place(x=130, y=110, width=180, height=25)
- # campo cursos
- etiqueta = ttk.Label(text="Cursos")
- etiqueta.place(x=10, y=160)
- lista_cursos = ttk.Combobox(
- state='readonly',
- values=['Python', 'JavaScript','Python & Django', 'C']
- )
- lista_cursos.place(x=130, y=160, width=180, height=25)
- # Casilla de verificación para aceptar términos y condiciones
- estado_casilla = tk.BooleanVar()
- estado_casilla.set("False")
- casilla = ttk.Checkbutton(text="Acepto términos y condiciones", variable=estado_casilla)
- casilla.place(x=100, y=230)
- boton = ttk.Button(text="Enviar datos", command=guardar_datos)
- boton.place(x=130, y=290, width=120, height=35)
- ventana.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement