Foro de elhacker.net

Programación => Scripting => Mensaje iniciado por: El mas antiguo en 17 Febrero 2022, 03:04 am



Título: Poner un scrollbar en un Treeview en tkinter
Publicado por: El mas antiguo en 17 Febrero 2022, 03:04 am
Hola gente ¿Cómo están?,
Alguien me podría guiar para hacer lo que dice el enunciado, probé poniendo mas productos de lo que se pueda visualizar pero la barra no aparece si en cambio con la ruedita del mouse se mueve en ambas direcciones.-

Código
  1. from tkinter import *
  2. import tkinter  as tk
  3. from tkinter import ttk
  4.  
  5. root = tk.Tk()
  6. root.title('Ejemplos de tablas')
  7. root.geometry('600x300')
  8. #root['bg']='#fb0'
  9.  
  10. tv = ttk.Treeview(root, columns=("col1", "col2"))
  11. tv.column("#0", width=200)
  12. tv.column("col1", width=80, anchor=CENTER)
  13. tv.column("col2", width=80, anchor=CENTER)
  14.  
  15.  
  16. tv.heading("#0", text="Producto", anchor=CENTER)
  17. tv.heading("col1", text="Precio", anchor=CENTER)
  18. tv.heading("col2", text="Stock", anchor=CENTER)
  19.  
  20. tv.insert("", END, text="Leche Ylolay TB x 1 litro", values=("130.50", "29"))
  21. tv.insert("", END, text="Tomate Arcor lata x 410 grs.", values=("106.00", "48"))
  22. tv.insert("", END, text="Aceite Zanoni botella x 900 cc.", values=("230.00", "11"))
  23.  
  24. tv.pack()
  25.  
  26. root.mainloop()


Slds. Daniel ☕☕☕


Título: Re: Poner un scrollbar en un Treeview en tkinter
Publicado por: reymosquito en 17 Febrero 2022, 08:08 am
es simple:

Código
  1. #-*- coding: utf  -8 -*-
  2. from tkinter import *
  3. import tkinter  as tk
  4. from tkinter import ttk
  5.  
  6. root = tk.Tk()
  7. root.title('Ejemplos de tablas')
  8. root.geometry('400x60')
  9.  
  10. #cambie las dimensiones porque es más rápido que ponerme a agregar elementos
  11.  
  12. tv = ttk.Treeview(root, columns=("col1", "col2"))
  13. tv.column("#0", width=200)
  14. tv.column("col1", width=80, anchor=CENTER)
  15. tv.column("col2", width=80, anchor=CENTER)
  16.  
  17.  
  18. tv.heading("#0", text="Producto", anchor=CENTER)
  19. tv.heading("col1", text="Precio", anchor=CENTER)
  20. tv.heading("col2", text="Stock", anchor=CENTER)
  21.  
  22. tv.insert("", END, text="Leche Ylolay TB x 1 litro", values=("130.50", "29"))
  23. tv.insert("", END, text="Tomate Arcor lata x 410 grs.", values=("106.00", "48"))
  24. tv.insert("", END, text="Aceite Zanoni botella x 900 cc.", values=("230.00", "11"))
  25.  
  26. tv.pack(side='left') # supongo que sabes usar pack
  27. ejscrollbar= ttk.Scrollbar(root,orient=VERTICAL,command=tv.yview)
  28. ejscrollbar.pack(side='right',fill='y')
  29. tv.configure(yscrollcommand=ejscrollbar.set)
  30.  
  31. root.mainloop()
  32.  


Título: Re: Poner un scrollbar en un Treeview en tkinter
Publicado por: El mas antiguo en 17 Febrero 2022, 13:30 pm
Hola reymosquito, gracias funciona a la perfección.-
Por el momento me voy a poner a buscar como moverlo dentro de la ventana(desconozco si se puede) estéticamente no me gusta como aparece, el único que me agrada es “top” pero casi desaparece el Scroll,-

Slds. Daniel ☕☕☕


Título: Re: Poner un scrollbar en un Treeview en tkinter
Publicado por: El mas antiguo en 17 Febrero 2022, 20:54 pm
Bueno al fin lo logre, agregando esta línea y sin modificar otra cosa se posiciona en el lugar deseado, desconozco que pasa al mezclar pack() y place(), al parecer nada.-


Código
  1. tv.place(x=20, y=20)
  2.  
  3. root.mainloop()
  4.  

Slds. Daniel ☕☕☕