Python Forum
[Tkinter] How to configure scrollbar dimension?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] How to configure scrollbar dimension?
#1
Question 
How to configure scrollbar dimension like below, and let it move scrollbar's block automate with associated object current visible position percentage?

[Image: 111.jpg]
Reply
#2
What GUI? Tk? Qt? How are you making the scrollbar? What is the scrollbar supposed to do? Probably best if you make a small example that demonstrates your problem and post the code.
Reply
#3
from tkinter import Tk, Listbox, Scrollbar

root_window = Tk()

list_1 = Listbox(root_window, height = 5)
list_1.grid(row = 0, column = 0)

vsb = Scrollbar(root_window, orient = 'vertical', command = list_1.yview)
vsb.grid(row = 0, column = 1)

list_1.configure(yscrollcommand = vsb.set)

list_1.insert('end', 'item-1')
list_1.insert('end', 'item-2')
list_1.insert('end', 'item-3')
list_1.insert('end', 'item-4')
list_1.insert('end', 'item-5')
list_1.insert('end', 'item-6')
list_1.insert('end', 'item-7')
list_1.insert('end', 'item-8')
list_1.insert('end', 'item-9')
list_1.insert('end', 'item-10')

root_window.mainloop()
[Image: 2.jpg]

This' my want:
[Image: 1.jpg]

Thanks.
Reply
#4
from tkinter import Tk, Listbox, Scrollbar
 
root_window = Tk()
 
list_1 = Listbox(root_window, height = 5)
list_1.grid(row = 0, column = 0)
 
vsb = Scrollbar(root_window, orient = 'vertical', command = list_1.yview)
vsb.grid(row = 0, column = 1, sticky='NSW')
 
list_1.configure(yscrollcommand = vsb.set)
 
list_1.insert('end', 'item-1')
list_1.insert('end', 'item-2')
list_1.insert('end', 'item-3')
list_1.insert('end', 'item-4')
list_1.insert('end', 'item-5')
list_1.insert('end', 'item-6')
list_1.insert('end', 'item-7')
list_1.insert('end', 'item-8')
list_1.insert('end', 'item-9')
list_1.insert('end', 'item-10')
 
root_window.mainloop()
Reply
#5
I usually use pack- fill=X but for grid try:
vsb.grid(row = 0, column = 1,columnspan=2, sticky='n' + 's')
Reply
#6
Got it, use 'sticky' stretch the 'scrollbar'.
Wink
Reply
#7
You should read up on the layout managerz place, pack and grid
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Help create scrollbar in chatbot with tkinter on python fenec10 4 1,548 Aug-07-2023, 02:59 PM
Last Post: deanhystad
  [Tkinter] Scrollbar apffal 7 3,152 Oct-11-2021, 08:26 PM
Last Post: deanhystad
Question [Tkinter] Can I configure 'tab' widgets state to 'disabled'? water 2 3,577 Jan-02-2021, 08:29 PM
Last Post: water
  [PyQt] scrollbar in tab issac_n 1 3,615 Aug-04-2020, 01:33 PM
Last Post: deanhystad
  [Tkinter] Scrollbar in tkinter PatrickNoir 2 3,329 Jul-26-2020, 06:02 PM
Last Post: deanhystad
  [Tkinter] Help with Scrollbar JJota 6 3,677 Mar-10-2020, 05:25 AM
Last Post: Larz60+
  [Tkinter] Scrollbar doesn't work on Canvas in Tkinter DeanAseraf1 3 9,389 Sep-19-2019, 03:26 PM
Last Post: joe_momma
  Configure label from different class storzo 1 4,118 Aug-19-2019, 01:30 PM
Last Post: Denni
  [Tkinter] Same Scrollbar for two text area smabubakkar 3 2,876 Jun-19-2019, 05:26 PM
Last Post: Denni
  Scrollbar rturus 5 17,561 Jun-06-2019, 01:04 PM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020