Advertisement
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
- def saludar():
- nombre = caja.get()
- print(f"Hola {nombre}")
- caja.delete(0, tk.END) #borro la caja
- def seleccion_lista():
- seleccion = lista.get(lista.curselection())
- print(seleccion)
- def seleccion_combo():
- seleccion = combo.get()
- print(seleccion)
- ventana = tk.Tk()
- ventana.title("Mi primera app")
- ventana.config(width=400, height=800)
- #ventana.resizable(0,0) # impide redimensionar la ventana
- # boton
- boton = ttk.Button(text="Saludar", command=saludar)
- boton.place(x=50, y=10, width=100, height=50)
- # agrego una caja de texto para ingresar un nombre
- caja = ttk.Entry()
- caja.place(x=10, y=80)
- # agrego una etiqueta
- label = ttk.Label(text="Nombre")
- label.place(x=150, y=80)
- # imagen dentro de una etiqueta
- imagen = tk.PhotoImage(file="camion.png")
- label = ttk.Label(image=imagen)
- label.place(relx=0.50, rely=0.50, relwidth=1.0, relheight=1.0)
- # lista (listbox)
- lista = tk.Listbox()
- lista.insert(0,"C++", "Java", "Python", "R")
- lista.place(x=10, y=120)
- boton = ttk.Button(text="Seleccionar", command=seleccion_lista)
- boton.place(x=10, y=300)
- # lista desplegable (combobox)
- combo = ttk.Combobox(state="readonly", values=["Ana","Tito","Juana","Oscar"])
- combo.place(x=10, y=330)
- boton = ttk.Button(text="Seleccionar", command=seleccion_combo)
- boton.place(x=10, y=360)
- # casilla de verificación
- estado_casilla = tk.BooleanVar()
- estado_casilla.set("True")
- casilla = ttk.Checkbutton(text="Aceptar las condiciones", variable=estado_casilla)
- casilla.place(x=10, y=400)
- # barra de progreso
- barra = ttk.Progressbar(maximum=100)
- barra.place(x=10, y=450, width=200)
- barra.step(50)
- barra.start(50)
- # barra vertical
- barra = ttk.Progressbar(maximum=100, orient=tk.VERTICAL)
- barra.place(x=300, y=450, height=200)
- barra.step(50)
- barra.start(10)
- # barra con progreso indeterminado
- barra = ttk.Progressbar(maximum=100, mode="indeterminate")
- barra.place(x=10, y=500, width=200)
- barra.start(10)
- ventana.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement