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
- ################# Funciones ##########################
- def imprimir_saludo():
- print("Botón presionado")
- def imprimir_otro_saludo():
- print("Otro botón presionado")
- def guardar_nombre():
- nombre = caja_de_texto.get()
- if nombre:
- print(f"Nombre '{nombre}' guardado")
- def imprimir_listbox():
- eleccion = lista.curselection()
- print(lista.get(eleccion))
- def imprimir_combobox():
- print(lista_combobox.get())
- ##################### main #############################
- ventana = tk.Tk()
- ventana.title("Posicionamiento place")
- ventana.config(width=400, height=800)
- # un boton con alto y ancho según texto
- boton = ttk.Button(text="Presionar", command=imprimir_saludo)
- boton.place(x=150, y=10)
- # otra forma de llamar a un boton con medidas propias
- boton = ttk.Button(command=imprimir_otro_saludo)
- boton.config(text="Soy otro botón")
- boton.place(x=150, y=70, width=100, height=50)
- # etiquetas estáticas
- etiqueta = ttk.Label(text="Guarde los datos")
- etiqueta.place(x=160, y=120)
- # 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)
- ########### boton con caja de texto y etiqueta #################3
- caja_de_texto = ttk.Entry()
- caja_de_texto.place(x=10,y=70)
- # agrego un texto por defecto en la caja
- caja_de_texto.insert(0, "Ej: Alejandro Luis")
- # borro 'Ej: '
- caja_de_texto.delete(0,4)
- # borro todos los textos
- # caja_de_texto.delete(0, tk.END)
- etiqueta = ttk.Label(text="Ingrese su nombre")
- etiqueta.place(x=20, y=50)
- # mi forma preferida de usar un botón
- boton = ttk.Button(text="Guardar el nombre", command=guardar_nombre)
- boton.place(x=20, y=110, width=120, height=35)
- ################### LISTAS (LISTBOX) ########################
- lista = tk.Listbox()
- lista.insert(0, "Python", "C", "C++", "Java", "Erlang")
- lista.place(x=10, y=150)
- boton = ttk.Button(text="Imprimir", command=imprimir_listbox)
- boton.place(x=10, y=320)
- ################### LISTAS DESPLEGABLES (COMBOBOX) ########################
- lista_combobox = ttk.Combobox(
- state="readonly",
- values = [
- "Visual Basic",
- "JavaScript",
- "Go",
- "R",
- "Rust"
- ]
- )
- lista_combobox.place(x=10, y=380)
- boton = ttk.Button(text="Imprimir selección", command=imprimir_combobox)
- boton.place(x=10, y=420)
- ################# CASILLA DE VERIFICACION ################
- estado = tk.BooleanVar() # declaro una variable booleana
- estado.set("False") # inicializo la variable
- casilla = ttk.Checkbutton(text="Opcion", variable=estado)
- casilla.place(x=10, y=480)
- ventana.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement