Posts: 28
Threads: 16
Joined: Oct 2020
Jan-02-2021, 03:41 PM
(This post was last modified: Jan-02-2021, 03:41 PM by water.)
How to configure scrollbar dimension like below, and let it move scrollbar's block automate with associated object current visible position percentage?
Posts: 6,799
Threads: 20
Joined: Feb 2020
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.
Posts: 28
Threads: 16
Joined: Oct 2020
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()
This' my want:
Thanks.
Posts: 6,799
Threads: 20
Joined: Feb 2020
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()
Posts: 165
Threads: 7
Joined: Nov 2018
I usually use pack- fill=X but for grid try:
vsb.grid(row = 0, column = 1,columnspan=2, sticky='n' + 's')
Posts: 28
Threads: 16
Joined: Oct 2020
Got it, use 'sticky' stretch the 'scrollbar'.
Posts: 6,799
Threads: 20
Joined: Feb 2020
You should read up on the layout managerz place, pack and grid
|