teslariu

more widgets

Sep 7th, 2022
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.00 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Algunos widgets
  4.  
  5. import tkinter as tk
  6. from tkinter import ttk
  7. from tkinter import messagebox
  8.  
  9. def listado():
  10.     seleccion = lista.get(lista.curselection())
  11.     print(seleccion)
  12.    
  13. def lista_combobox():
  14.     print(combobox.get())
  15.  
  16. ventana = tk.Tk()
  17. ventana.config(width=500, height=800)
  18.  
  19. label = ttk.Label(text="Soy una etiqueta")
  20. label.place(x=30, y=50)
  21.  
  22. # imagen dentro de una etiqueta
  23. imagen = tk.PhotoImage(file="camion.png")
  24. label = ttk.Label(image=imagen)
  25. label.place(relx=0.5, rely=0.5, relwidth=0.5, relheight=0.5)
  26.  
  27. # listbox
  28. lista = tk.Listbox()
  29. lista.insert(0,"Ana","Abel","Juana","Oscar")
  30. lista.place(x=10, y=100)
  31. boton = ttk.Button(text="Elegir", command=listado)
  32. boton.place(x=10, y=270)
  33.  
  34. # lista desplegable
  35. combobox = ttk.Combobox(state="readonly", values=["C++","Java","Python"])
  36. combobox.place(x=10, y=300)
  37. boton = ttk.Button(text="Elegir", command=lista_combobox)
  38. boton.place(x=10, y=330)
  39.  
  40. # casilla de verificacion
  41. estado = tk.BooleanVar()
  42. estado.set("False")
  43. casilla = ttk.Checkbutton(text="Acepto términos y condiciones", variable=estado)
  44. casilla.place(x=10, y=380)
  45.  
  46. # barra de progreso
  47. barra = ttk.Progressbar(maximum=100)
  48. barra.place(x=10, y=450, width=200)
  49. barra.step(99.9)
  50. barra.start(75)
  51.  
  52. barra = ttk.Progressbar(maximum=100, orient=tk.VERTICAL)
  53. barra.place(x=300, y=450, height=200)
  54. barra.step(25)
  55. barra.start(50)
  56.  
  57. ##### cuadros de dialogo ###############
  58.  
  59. # siempre retornan OK
  60. messagebox.showinfo(title="INFO",message="Apriete para continuar")
  61. messagebox.showwarning(title="OJO",message="¿Está seguro de lo que va a hacer?")
  62. messagebox.showerror(title="ERROR",message="JAJA.. dejá, no hagas nada")
  63.  
  64. # retornan True or False
  65. respuesta = messagebox.askokcancel(title="Pregunta",message="¿Desea continuar")
  66. respuesta = messagebox.askyesno(title="DUDA",message="¿Sabe lo que está haciendo?")
  67. respuesta = messagebox.askretrycancel(title="AYUDA",message="Pruebe de nuevo")
  68.  
  69.  
  70.  
  71.  
  72.  
  73. ventana.mainloop()
Add Comment
Please, Sign In to add comment