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 as mb
- def guardar_nombre():
- data = nombre.get()
- print(data)
- def elegir():
- nombre = lista.get(lista.curselection())
- print(nombre)
- def seleccion():
- print(combo.get())
- ventana = tk.Tk()
- ventana.title("Mi primera app")
- ventana.config(width=400, height=800)
- # ventana.resizable(0,0)
- # boton
- boton = ttk.Button(text="Guardar nombre",command=guardar_nombre)
- boton.place(x=50, y=10, width=120, height=50)
- # campo nombre
- etiqueta = ttk.Label(text="Nombre")
- etiqueta.place(x=200, y=10)
- nombre = ttk.Entry()
- nombre.place(x=250, y=10)
- # lista (listbox)
- lista = tk.Listbox()
- lista.insert(0, "Juan","Ana","Oscar","Rodrigo")
- lista.place(x=10, y=100)
- boton = ttk.Button(text="Elegir nombre",command=elegir)
- boton.place(x=20, y=270, width=100, height=30)
- # lista desplegable
- combo = ttk.Combobox(
- state="readonly",
- values=["C++","Python","Java","Go","Ruby"]
- )
- combo.place(x=20, y=320)
- boton = ttk.Button(text="Seleccionar",command=seleccion)
- boton.place(x=20, y=380)
- # 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.50)
- # casilla de verificacion
- estado = tk.BooleanVar()
- estado.set("False")
- casilla = ttk.Checkbutton(text="Aceptar términos y condiciones", variable=estado)
- casilla.place(x=170, y=100)
- # barra de progreso
- barra = ttk.Progressbar(maximum=100)
- barra.place(x=10, y=450, width=200)
- barra.step(20)
- barra.start(5)
- barra = ttk.Progressbar(maximum=100, orient=tk.VERTICAL)
- barra.place(x=300, y=450, height=200)
- barra.step(40)
- barra.start(5)
- ############# cuadros de dialogo #######################
- # de info
- mb.showinfo(title="INFO", message="HA PASADO muucho tiempo...")
- mb.showwarning(title="advertencia", message="Ojo con el piojo...")
- mb.showerror(title="ERROR", message="Has errado...")
- # condicionales
- resp1 = mb.askokcancel(title="Pregunta", message="¿Desea continuar")
- resp2 = mb.askyesno(title="Confirmación", message="¿Desea guardar los datos?")
- resp3 = mb.askretrycancel(title="Pregunta", message="¿Reintenta nuevamente")
- ventana.mainloop()
Add Comment
Please, Sign In to add comment