teslariu

widgets place

Dec 7th, 2022
1,093
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.09 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. import tkinter as tk
  5. from tkinter import ttk
  6. from tkinter import messagebox
  7.  
  8. def imprimir_listbox():
  9.     seleccion = lista.get(lista.curselection())
  10.     print(seleccion)
  11.  
  12. def imprimir_combo():
  13.     seleccion = combo.get()
  14.     print(seleccion)
  15.  
  16.  
  17.  
  18. ventana = tk.Tk()
  19. ventana.title("Posicionamiento place")
  20. ventana.config(width=400, height=800)
  21.  
  22. # etiquetas
  23. label = ttk.Label(text="Hola")
  24. label.place(x=160, y=120)
  25.  
  26. # imagen dentro de etiqueta
  27. imagen = tk.PhotoImage(file="camion2.png")
  28. label = ttk.Label(image=imagen)
  29. label.place(relx=0.5, rely=0.5, relwidth=0.5, relheight=0.5)
  30.  
  31. # lista (listbox)
  32. lista = tk.Listbox()
  33. lista.insert(0, "Python","C","Java","Go")
  34. lista.place(x=10, y=100)
  35. boton = ttk.Button(text="Seleccionar", command=imprimir_listbox)
  36. boton.place(x=10, y=270)
  37.  
  38. # lista desplegable (combobox)
  39. combo = ttk.Combobox(state="readonly",
  40.                     values=("Juan","Pedro","Ana")
  41.                     )
  42. combo.place(x=10, y=300)
  43. boton = ttk.Button(text="Seleccionar", command=imprimir_combo)
  44. boton.place(x=10, y=330)
  45.  
  46. # casilla de verificación
  47. estado = tk.BooleanVar()
  48. estado.set("False")
  49. casilla = ttk.Checkbutton(text="Acepto términos y condiciones", variable=estado)
  50. casilla.place(x=10, y=380)
  51.  
  52. # barra de progreso
  53. barra = ttk.Progressbar(maximum=100)
  54. barra.place(x=10, y=450, width=200)
  55. barra.step(10)
  56. barra.start(70)
  57.  
  58. barra = ttk.Progressbar(maximum=100, orient=tk.VERTICAL)
  59. barra.place(x=300, y=450, height=200)
  60. barra.step(10)
  61. barra.start(70)
  62.  
  63. # cuadros de dialogo
  64.  
  65. # siempre retornan True
  66. messagebox.showinfo(title="OJITO", message="Fijate bien lo que haces...")
  67. messagebox.showwarning(title="ESPERA", message="No hagas macanaas...")
  68. messagebox.showerror(title="FUISTE", message="Estas al horno...")
  69.  
  70. # Retornan True of False
  71. eleccion1 = messagebox.askokcancel(title="Pregunta", message="¿Seguimos?")
  72. eleccion2 = messagebox.askyesno(title="Backup", message="Iniciar copia de respaldo")
  73. eleccion3 = messagebox.askretrycancel(title="error", message="Probar de nuevo")
  74.  
  75.  
  76.  
  77.  
  78.  
  79. ventana.mainloop()
  80.  
Advertisement
Add Comment
Please, Sign In to add comment