Advertisement
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
- def clic():
- nombre = caja_nombre.get()
- print(nombre)
- def clic_lista():
- seleccion = lista.get(lista.curselection())
- print(seleccion)
- def clic_combo():
- seleccion = combobox.get()
- print(seleccion)
- ventana = tk.Tk()
- ventana.title("Mi primera app")
- ventana.config(width=400, height=600)
- # ventana.resizable(0,0) impide modificar el tamaño inicial
- # boton con caja de texto
- caja_nombre = ttk.Entry()
- caja_nombre.place(x=70,y=40,width=200,height=25)
- label = ttk.Label(text="Nombre")
- label.place(x=10, y=40)
- boton = ttk.Button(text="Guardar", command=clic)
- boton.place(x=30, y=80)
- # mostrar una 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.5)
- # lista
- lista = tk.Listbox()
- lista.insert(0,"Python","C++","Java","Go")
- lista.place(x=10, y=120)
- boton = ttk.Button(text="Guardar", command=clic_lista)
- boton.place(x=10, y=300)
- # lista desplegable (combobox)
- combobox = ttk.Combobox(
- state="readonly",
- values=[1,2,3,4,5,"Ana","Luis"]
- )
- combobox.place(x=10,y=340)
- boton = ttk.Button(text="Guardar", command=clic_combo)
- boton.place(x=10, y=380)
- # casilla de verificación
- estado = tk.BooleanVar()
- estado.set("False")
- casilla = ttk.Checkbutton(text="Acepto los términos y condiciones",variable=estado)
- casilla.place(x=10,y=420)
- # barra de progreso
- barra = ttk.Progressbar(maximum=100)
- barra.place(x=10, y=450, width=200)
- barra.step(20)
- barra.start(10)
- barra = ttk.Progressbar(maximum=100, orient=tk.VERTICAL)
- barra.place(x=300, y=300, height=200)
- barra.step(50)
- barra.start(10)
- # cuadros de dialogo
- messagebox.showinfo(title="INFO", message="LO ESTOY ESPIANDO")
- messagebox.showwarning(title="Advertencia", message="Me estoy impacientando")
- messagebox.showerror(title="ERROR", message="¿Acaso no sabe sumar?")
- # cuadros que retornan True o False
- decision = messagebox.askokcancel(title="Pregunta", message="¿Desea salir")
- decision = messagebox.askyesno(title="Pregunta", message="¿Desea salir")
- decision = messagebox.askretrycancel(title="Pregunta", message="¿Desea reintentar")
- ventana.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement