teslariu

widget

Feb 25th, 2022
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.53 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # posicionamiento place
  5.  
  6. def seleccion_listbox():
  7.     opcion = lista.get(lista.curselection())
  8.     print(opcion)
  9.    
  10. def seleccion_combo():
  11.     opcion = combo.get()
  12.     print(opcion)
  13.  
  14.  
  15. import tkinter as tk
  16. from tkinter import ttk
  17. from tkinter import messagebox
  18.  
  19.  
  20. ventana = tk.Tk()
  21. ventana.title("Posicionamiento place")
  22. ventana.config(width=400, height=800, bg="gray")
  23.  
  24. # imagen dentro de una etiqueta
  25. imagen_camion = tk.PhotoImage(file="camion.png")
  26. label = ttk.Label(image=imagen_camion)
  27. label.place(relx=0.5, rely=0.5, relwidth=0.50, relheight=0.50)
  28.  
  29. # lista fija (listbox)
  30. lista = tk.Listbox()
  31. lista.insert(0,"Python","Erlang","Java","GO")
  32. lista.place(x=10, y=50)
  33. boton = ttk.Button(text="Seleccionar", command=seleccion_listbox)
  34. boton.place(x=10, y=220)
  35.  
  36. # lista desplegable (combobox)
  37. combo = ttk.Combobox(state="readonly", values=[0,1,2,3,4,5,6,7,8,9,10])
  38. combo.place(x=10, y=250)
  39. boton = ttk.Button(text="Seleccionar", command=seleccion_combo)
  40. boton.place(x=10, y=280)
  41.  
  42. # casilla de verificacion
  43. seleccion = tk.BooleanVar()
  44. seleccion.set("False")
  45. casilla = ttk.Checkbutton(text="Acepto términos y condiciones", variable=seleccion)
  46. casilla.place(x=10, y=330)
  47.  
  48. # barra de progreso
  49. barra = ttk.Progressbar(maximum=100)
  50. barra.place(x=10, y=400, width=200)
  51. barra.step(20)
  52.  
  53. barra = ttk.Progressbar(orient=tk.VERTICAL, maximum=100)
  54. barra.place(x=300, y=400, height=200)
  55. barra.step(50)
  56.  
  57. barra.start(5) # por defecto aumenta cada 50 miliseg
  58.  
  59.  
  60.  
  61. #######  pestañas ####################
  62. panel = ttk.Notebook()
  63. panel.place(x=20, y=500)
  64.  
  65. pestaña_alumni = ttk.Label(panel,text="El aula virtual está en alumni.education")
  66. pestaña_google = ttk.Label(panel,text="El buscador a usar es google.com.ar")
  67.  
  68. panel.add(pestaña_alumni, text="Alumni", padding=20)
  69. panel.add(pestaña_google, text="Buscador", padding=20)
  70.  
  71.  
  72. ########## cuadros de dialogo #######################
  73.  
  74. # siempre retornan OK
  75. r = messagebox.showinfo(title="INFO", message="Ultima clase")
  76. print(r)
  77. r = messagebox.showwarning(title="OJO", message="Estudien para los exámenes")
  78. print(r)
  79. r = messagebox.showerror(title="ERROR", message="2 x 8 no es 15")
  80. print(r)
  81.  
  82. # retornan True of False
  83. opcion = messagebox.askokcancel(title="Pregunta", message="¿Quiere salir")
  84. print(opcion)
  85. opcion = messagebox.askyesno(title="Edad", message="¿Es mayor de 18 años?")
  86. print(opcion)
  87. opcion = messagebox.askretrycancel(title="Pregunta", message="¿Desea intentarlo nuevamente")
  88. print(opcion)
  89.  
  90.  
  91.  
  92.  
  93.  
  94. ventana.mainloop()
  95.  
Add Comment
Please, Sign In to add comment