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 guardar_nombre():
- nombre = caja.get()
- print(f"Nombre '{nombre}' guardado")
- def otro_saludo():
- print("Otro botón presionado")
- def listbox():
- try:
- seleccion = lista.get(lista.curselection())
- except:
- print("No ha seleccionado nada")
- else:
- print(f"Ha elegido {seleccion}")
- def combobox():
- print(lista_desplegable.get())
- ventana = tk.Tk()
- ventana.title("Posicionamiento place")
- ventana.config(width=400, height=800)
- # boton con ancho y alto
- boton = ttk.Button(text="Chau mundo", command=otro_saludo)
- boton.place(x=150, y=70, width=100, height=50)
- # etiquetas que almacena una imagen
- imagen = tk.PhotoImage(file="camion.png")
- etiqueta = ttk.Label(image=imagen)
- etiqueta.place(relx=0.5, rely=0.5, relwidth=0.5, relheight=0.5)
- # caja de texto
- caja = ttk.Entry()
- caja.place(x=10, y=40)
- caja.insert(0, "Inserte su nombre...")
- # boton con ancho y alto por defecto (según el tamaño del texto)
- boton = ttk.Button(text="Guardar", command=guardar_nombre)
- boton.place(x=50, y=10)
- # lista (listbox)
- lista = tk.Listbox()
- lista.insert(0, "Python", "C", "C++", "Java", "Perl")
- lista.place(x=10, y=100)
- boton = ttk.Button(text="Guardar selección", command=listbox)
- boton.place(x=10, y=270)
- # lista desplegable (combobox):
- lista_desplegable = ttk.Combobox(state="readonly",
- values = [
- "JavaScript",
- "Erlang",
- "Visual Basic"
- ]
- )
- lista_desplegable.place(x=10, y=300)
- boton = ttk.Button(text="Imprimir selección", command=combobox)
- boton.place(x=10,y=330)
- # casilla de verificación:
- estado = tk.BooleanVar()
- estado.set("True")
- casilla = ttk.Checkbutton(text="Marcar por SI", variable=estado)
- casilla.place(x=10, y=380)
- ventana.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment