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 pprint import pprint
- from tkinter import ttk
- from tkinter import messagebox
- def saludar():
- global nombres
- nombres.append(caja.get())
- pprint(nombres)
- caja.delete(0, tk.END)
- def op_lista():
- opcion = lista.get(lista.curselection())
- print(opcion)
- def op_combo():
- opcion = combo.get()
- print(opcion)
- nombres = []
- ventana = tk.Tk()
- ventana.title("Ventana con place")
- ventana.config(width=400, height=800)
- boton = ttk.Button(text="Guardar nombre", command=saludar)
- boton.place(x=30, y=10, width=100, height=40)
- etiqueta = ttk.Label(text="Nombre:")
- etiqueta.place(x=150, y=20)
- caja = ttk.Entry()
- caja.place(x=200, y=20, width=150, height=25)
- # lista (listbox)
- lista = tk.Listbox()
- lista.insert(0,"Python","C","Java","Go")
- lista.place(x=10, y=100)
- boton = ttk.Button(text="Guardar elección", command=op_lista)
- boton.place(x=10, y=270)
- # lista desplegable (combobox)
- combo = ttk.Combobox(state="readonly", values=[1,20,50,145,1000])
- combo.place(x=10,y=300)
- boton = ttk.Button(text="Guardar elección", command=op_combo)
- boton.place(x=10, y=330)
- # imagen dentro de una etiqueta
- 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 verificación
- estado = tk.BooleanVar()
- estado.set("False")
- casilla = ttk.Checkbutton(text="Acepto términos y condiciones", variable=estado)
- casilla.place(x=10, y=380)
- # barra de progreso
- barra = ttk.Progressbar(maximum=100)
- barra.place(x=10, y=450, width=200)
- barra.step(50)
- barra.start(20)
- # barra vertical
- barra = ttk.Progressbar(orient=tk.VERTICAL, maximum=100)
- barra.place(x=300, y=450, height=200)
- barra.step(50)
- barra.start(20)
- ###### cuadros de dialogo
- # devuelven True or False
- messagebox.askokcancel(title="Pregunta", message="¿Desea seguir?")
- messagebox.askyesno(title="Pregunta", message="¿Seguro desea seguir?")
- messagebox.askretrycancel(title="Pregunta", message="¿Desea reintentar?")
- # devuelven ok
- messagebox.showinfo(title="Info", message="Se ha guardado el registro")
- messagebox.showwarning(title="Advertencia", message="Ojo, no se equivoque")
- messagebox.showerror(title="Error", message="Está en el horno...")
- ventana.mainloop()
Add Comment
Please, Sign In to add comment