Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- # PLACE
- import tkinter as tk
- from tkinter import ttk
- from tkinter import messagebox
- def guardar():
- from pprint import pprint
- global personas
- nombre = caja_nombre.get()
- if not nombre or nombre.isspace():
- messagebox.showerror(title="Advertencia", message="Nombre inválido")
- return
- email = caja_email.get()
- persona = {"nombre": nombre, "email":email}
- personas.append(persona)
- pprint(personas)
- caja_email.delete(0,tk.END)
- caja_nombre.delete(0,tk.END)
- def guardar_lista():
- cursor = lista.curselection()
- curso = lista.get(cursor)
- print(curso)
- def guardar_combo():
- valor = combobox.get()
- print(valor)
- # personas = [{"nombre":"Ale", "email":"ale@ale.com"}, {}, ...]
- personas = []
- ######## parte grafica #################
- ventana = tk.Tk()
- ventana.title("Mi app")
- # ventana.resizable(False,False)
- ventana.config(width=400, height=800)
- # campos de datos
- # campo nombre
- etiqueta = tk.Label(text="Nombre")
- etiqueta.place(x=30, y=10)
- caja_nombre = tk.Entry()
- caja_nombre.place(x=100, y=10, width=150, height=25)
- # campo email
- etiqueta = tk.Label(text="Email")
- etiqueta.place(x=30, y=60)
- caja_email = tk.Entry()
- caja_email.place(x=100, y=60, width=150, height=25)
- # boton
- boton = ttk.Button(text="Guardar", command=guardar)
- boton.place(x=120, y=120, width=80, height=35)
- # lista
- lista = tk.Listbox()
- lista.insert(0,"Python","C","Java")
- lista.place(x=10, y=180)
- boton = ttk.Button(text="Guardar", command=guardar_lista)
- boton.place(x=50, y=370)
- # lista desplegable
- combobox = ttk.Combobox(
- state="readonly",
- values = ("Juan", "Ana", "Guillermina", "Victor")
- )
- combobox.place(x=50,y=400)
- boton = ttk.Button(text="Guardar", command=guardar_combo)
- boton.place(x=50, y=430)
- # imagen dentro de una etiqueta
- imagen = tk.PhotoImage(file="camion.png")
- label = ttk.Label(image=imagen)
- label.place(relx=0.5, rely=0.5, relwidth=0.5, relheight=0.5)
- # casilla de verificacion
- estado = tk.BooleanVar()
- estado.set("False")
- casilla = ttk.Checkbutton(text="Aceptar términos y condiciones", variable=estado)
- casilla.place(x=50, y=480)
- ventana.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement