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 saludar():
- nombre = caja.get()
- if nombre:
- print(f"Hola {nombre}") # lo muestra por consola
- saludo.set(f"Hola {nombre}") # lo muestra en entorno gráfico
- else:
- print(f"Hola desconocido")
- caja.delete(0,tk.END)
- def seleccion_lista():
- seleccion = lista.get(lista.curselection())
- print(f"Selección: {seleccion}")
- def seleccion_combo():
- seleccion = combo.get()
- print(f"Selección: {seleccion}")
- root = tk.Tk()
- root.title("Posicionamiento place")
- root.config(width=400, height=800, bg="sky blue")
- saludo = tk.StringVar() # creo la variable gráfica para mostrar el saludo
- saludo.set("desconocido") #la inicializo
- # boton con caja de texto y etiqueta
- caja = ttk.Entry() # caja para ingresar el nombre
- caja.place(x=10, y=40, width=100, height=25)
- label = tk.Label(text="Nombre", bg="sky blue", font=["arial",12,"bold","italic"])
- label.place(x=130, y=40)
- boton = ttk.Button(text="Saludar", command=saludar)
- boton.place(x=90, y=80)
- # caja para mostrar el saludo
- caja_saludo = ttk.Entry(
- textvariable=saludo,
- state=tk.DISABLED
- )
- caja_saludo.place(x=10, y=120, width=180, height=25)
- # lista desplegada (listbox)
- lista = tk.Listbox()
- lista.insert(0, "Python","GO","JAVA","Erlang","C++")
- lista.place(x=10, y=170)
- boton = ttk.Button(text="Seleccionar", command=seleccion_lista)
- boton.place(x=10, y=350)
- # lista desplegable (combobox)
- combo = ttk.Combobox(state="readonly", values=[1,2,3,4,5,6,7,8])
- combo.place(x=10, y=400)
- boton = ttk.Button(text="Seleccionar", command=seleccion_combo)
- boton.place(x=10, y=450)
- # casilla de verificacion
- estado = tk.BooleanVar()
- estado.set("False")
- casilla = tk.Checkbutton(text="Acepta las condiciones", variable=estado, bg="sky blue")
- casilla.place(x=10, y=500)
- # barra de progreso
- barra = ttk.Progressbar(maximum=100)
- barra.place(x=10, y=550, width=200)
- # "coloreo" la barra
- barra.step(25)
- # le doy movimiento
- barra.start(10)
- barra = ttk.Progressbar(orient=tk.VERTICAL)
- barra.place(x=350, y=550, height=200)
- barra.step(90)
- barra.start()
- # 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)
- # cuadros de dialogo
- # siempre retorna la cadena "ok"
- messagebox.showinfo(title="INFO", message="Lo estoy observando...")
- messagebox.showwarning(title="ADVERTENCIA", message="Ojo...")
- messagebox.showerror(title="ERROR", message="Mejor no haga nada...")
- # siempre retorna True of False"
- messagebox.askokcancel(title="Pregunta", message="¿Desea salir?")
- messagebox.askyesno(title="Pregunta", message="Decídase")
- messagebox.askretrycancel(title="Pregunta", message="¿Desea reintentarlo?")
- root.mainloop()
Add Comment
Please, Sign In to add comment