Advertisement
teslariu

widget

Sep 27th, 2021
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.04 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.  
  7. def saludar():
  8.     nombre = caja.get()
  9.     print(f"Hola {nombre}")
  10.     caja.delete(0, tk.END) #borro la caja
  11.  
  12. def seleccion_lista():
  13.     seleccion = lista.get(lista.curselection())
  14.     print(seleccion)
  15.  
  16. def seleccion_combo():
  17.     seleccion = combo.get()
  18.     print(seleccion)
  19.  
  20.  
  21.  
  22.  
  23.  
  24. ventana = tk.Tk()
  25. ventana.title("Mi primera app")
  26. ventana.config(width=400, height=800)
  27. #ventana.resizable(0,0)  # impide redimensionar la ventana
  28.  
  29. # boton
  30. boton = ttk.Button(text="Saludar", command=saludar)
  31. boton.place(x=50, y=10, width=100, height=50)
  32.  
  33. # agrego una caja de texto para ingresar un nombre
  34. caja = ttk.Entry()
  35. caja.place(x=10, y=80)
  36.  
  37. # agrego una etiqueta
  38. label = ttk.Label(text="Nombre")
  39. label.place(x=150, y=80)
  40.  
  41. # imagen dentro de una etiqueta
  42. imagen = tk.PhotoImage(file="camion.png")
  43. label = ttk.Label(image=imagen)
  44. label.place(relx=0.50, rely=0.50, relwidth=1.0, relheight=1.0)
  45.  
  46. # lista (listbox)
  47. lista = tk.Listbox()
  48. lista.insert(0,"C++", "Java", "Python", "R")
  49. lista.place(x=10, y=120)
  50. boton = ttk.Button(text="Seleccionar", command=seleccion_lista)
  51. boton.place(x=10, y=300)
  52.  
  53. # lista desplegable (combobox)
  54. combo = ttk.Combobox(state="readonly", values=["Ana","Tito","Juana","Oscar"])
  55. combo.place(x=10, y=330)
  56. boton = ttk.Button(text="Seleccionar", command=seleccion_combo)
  57. boton.place(x=10, y=360)
  58.  
  59. # casilla de verificación
  60. estado_casilla = tk.BooleanVar()
  61. estado_casilla.set("True")
  62. casilla = ttk.Checkbutton(text="Aceptar las condiciones", variable=estado_casilla)
  63. casilla.place(x=10, y=400)
  64.  
  65.  
  66. # barra de progreso
  67. barra = ttk.Progressbar(maximum=100)
  68. barra.place(x=10, y=450, width=200)
  69. barra.step(50)
  70. barra.start(50)
  71.  
  72.  
  73. # barra vertical
  74. barra = ttk.Progressbar(maximum=100, orient=tk.VERTICAL)
  75. barra.place(x=300, y=450, height=200)
  76. barra.step(50)
  77. barra.start(10)
  78.  
  79. # barra con progreso indeterminado
  80. barra = ttk.Progressbar(maximum=100, mode="indeterminate")
  81. barra.place(x=10, y=500, width=200)
  82. barra.start(10)
  83.  
  84. ventana.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement