Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- # place.py
- import tkinter as tk
- from tkinter import ttk
- from tkinter import messagebox
- def clic():
- nombre = caja_nombre.get()
- print(nombre)
- def clic_listbox():
- seleccion = lista.get(lista.curselection())
- print(seleccion)
- def clic_combo():
- nombre = combo.get()
- print(nombre)
- ventana = tk.Tk()
- ventana.title("Place")
- ventana.config(width=400, height=600)
- ventana.resizable(True,True)
- ventana.minsize(300,300)
- # Etiqueta
- etiqueta = ttk.Label(text="Nombre")
- etiqueta.place(x=10, y=10)
- # caja de texto
- caja_nombre = ttk.Entry()
- caja_nombre.place(x=80, y=10, width=150, height=25)
- # Boton
- boton = ttk.Button(text="Guardar", command = clic)
- boton.place(x=120, y= 50, width=70, height=35)
- # etiqueta con una imgen
- 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)
- # Listbox
- lista = tk.Listbox()
- lista.insert(0, "Python", "C++", "Java", "Erlang")
- lista.place(x=10, y=150)
- boton = ttk.Button(text="Guardar", command = clic_listbox)
- boton.place(x=10, y= 350, width=70, height=35)
- # Combobox
- combo = ttk.Combobox(
- state="readonly",
- values = ["Andrea", "Juana", "Emilio"]
- )
- combo.place(x=10, y=450)
- boton = ttk.Button(text="Guardar", command = clic_combo)
- boton.place(x=10, y= 480, width=70, height=35)
- # 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=150, y=200)
- # barra de progreso
- barra = ttk.Progressbar(maximum=100)
- barra.place(x=10, y=550, width=300)
- barra.step(10)
- barra.start(3)
- barra = ttk.Progressbar(maximum=100, orient=tk.VERTICAL)
- barra.place(x=300, y=220, height=300)
- barra.step(50)
- barra.start(60)
- #### cuadros de dialogo
- # siempre retornan la cadena "ok"
- messagebox.showinfo(title="Información", message="Has sido despedido")
- messagebox.showwarning(title="Advertencia", message="Si no saluda lo despido")
- messagebox.showerror(title="Error", message="Te has equivocado")
- # retornan True or False
- respuesta = messagebox.askokcancel(title="Pregunta", message="¿Desea salir")
- if respuesta:
- print("Adios...")
- else:
- print("Sigamos entonces...")
- respuesta = messagebox.askyesno(title="Requisito", message="¿Es mayor de edad?")
- if respuesta:
- print("Puede beber")
- else:
- print("Prohibido beber...")
- respuesta = messagebox.askretrycancel(title="Pregunta", message="¿Desea reintentar")
- if respuesta:
- print("Probemos de nuevo...")
- else:
- print("Bueno, la proxima vez será...")
- ventana.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement