Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- import tkinter as tk
- from tkinter import ttk
- from tkinter import messagebox
- from pprint import pprint
- contactos = []
- def formulario():
- global contactos
- nombre = caja_nombre.get()
- tel = caja_tel.get()
- # chequeo si faltan datos
- if not len(nombre) or not len(tel):
- messagebox.showwarning(title='Advertencia', message='Formulario incompleto')
- return
- contacto = {"nombre":nombre, "telefono":tel}
- contactos.append(contacto)
- print()
- pprint(contactos)
- # borro el formulario
- caja_nombre.delete(0, tk.END)
- caja_tel.delete(0, tk.END)
- # muestro un mensaje de datos guardados
- messagebox.showinfo(title='Mensaje', message='Datos guardados')
- def ver_lista():
- valor = lista.get(lista.curselection())
- print(valor)
- def ver_combo():
- print(combo.get())
- root = tk.Tk()
- root.title("Posicionamiento place")
- root.config(width=400, height=800)
- # Campo nombre
- caja_nombre = ttk.Entry()
- caja_nombre.place(x=120, y=10, width=150, height=25)
- etiqueta = ttk.Label(text='Nombre')
- etiqueta.place(x=20, y=10)
- # Campo telefono
- caja_tel = ttk.Entry()
- caja_tel.place(x=120, y=60, width=150, height=25)
- etiqueta = ttk.Label(text='Teléfono')
- etiqueta.place(x=20, y=60)
- # boton
- boton = ttk.Button(text="Guardar", command=formulario)
- boton.place(x=130, y=100, height=50, width=100)
- ############## Widgets sueltos
- # lista estatica (listbox)
- lista = tk.Listbox()
- lista.insert(0,"Python","C++","Java","Go")
- lista.place(x=10, y=200)
- boton = ttk.Button(text="Guardar", command=ver_lista)
- boton.place(x=20, y=370)
- # lista desplegable (combobox)
- combo = ttk.Combobox(state="readonly", values=[1,2,45,67,778,'infinito'])
- combo.place(x=10, y=400)
- boton = ttk.Button(text="Guardar", command=ver_combo)
- boton.place(x=20, y=430)
- # imagen de fondo
- imagen = tk.PhotoImage(file='camion2.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="Acepto términos y condiciones", variable=estado)
- casilla.place(x=20, y=460)
- # barra de progreso
- barra = ttk.Progressbar(maximum=100)
- barra.place(x=10, y=500, width=200)
- barra.step(99.9)
- barra.start(10)
- barra = ttk.Progressbar(orient=tk.VERTICAL, maximum=100)
- barra.place(x=300, y=500, height=200)
- barra.step(30)
- barra.start(30)
- # mas cuadros de mensaje : estos retornan true or false
- messagebox.askokcancel(title='Pregunta', message='¿Desea cancelar?')
- messagebox.askyesno(title='Mensaje', message='¿Desea salir?')
- messagebox.askretrycancel(title='Duda existencial', message='Probar nuevamente')
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment