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
- from pprint import pprint
- personas = []
- # personas = [{"nombre": Juan, "email":"juands", "tel":4564546}]
- def guardar():
- global personas
- nombre = caja_nombre.get()
- email = caja_email.get()
- tel = caja_tel.get()
- persona = {"nombre":nombre, "email":email, "tel":tel}
- personas.append(persona)
- print()
- pprint(personas)
- caja_email.delete(0,tk.END)
- caja_nombre.delete(0,tk.END)
- caja_tel.delete(0,tk.END)
- def sel_lista():
- eleccion = lista.get(lista.curselection())
- print(eleccion)
- def sel_combo():
- eleccion = combobox.get()
- print(eleccion)
- ventana = tk.Tk()
- ventana.config(width=400, height=600)
- ventana.title("Mi primera app")
- # Campos de formularios
- # campo nombre
- etiqueta = ttk.Label(text="Nombre")
- etiqueta.place(x=10, y=20)
- caja_nombre = ttk.Entry()
- caja_nombre.place(x=100, y=20, width=180, height=25)
- # campo email
- etiqueta = ttk.Label(text="Email")
- etiqueta.place(x=10, y=70)
- caja_email = ttk.Entry()
- caja_email.place(x=100, y=70, width=180, height=25)
- # campo telefono
- etiqueta = ttk.Label(text="TE")
- etiqueta.place(x=10, y=120)
- caja_tel = ttk.Entry()
- caja_tel.place(x=100, y=120, width=180, height=25)
- boton = ttk.Button(text="Guardar", command=guardar)
- boton.place(x=120, y=180, width=120, height=50)
- # listbox
- lista = tk.Listbox()
- lista.insert(0,"Python", "Java", "Prolog")
- lista.place(x=10, y=250)
- boton = ttk.Button(text="Elegir", command=sel_lista)
- boton.place(x=150, y=350)
- # lista desplegable
- combobox = ttk.Combobox(state="readonly",values=[1,2,3,4,5,6])
- combobox.place(x=10,y=450)
- boton = ttk.Button(text="Elegir", command=sel_combo)
- boton.place(x=170, y=450)
- # retornan ok
- salir = messagebox.askokcancel(title="Pregunta",message="¿Desea salir?")
- # retornan siempre ok
- messagebox.showerror(title="Error", message="Estas equivocado")
- ventana.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment