0

When scrolled items by mouse wheel in tk.Listbox/ttk.Combobox, some items not shown.

Is it a bug ? or I did something wrong ?

In following case, 'Wednesday' will not shown when scroll mouse wheel at

  • tk.Listbox or vertical scrollbar of tk.Listbox, or
  • listbox of ttk.Combo
from tkinter import *
from tkinter import ttk

font = ('Courier New', 24)
lst = ('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday')

root = Tk()

frame1 = Frame(root)
frame1.pack(side=LEFT)
vsb1 = Scrollbar(frame1, orient='v')
vsb1.pack(side=RIGHT, fill='y')
var = StringVar()
var.set(lst)
listbox = Listbox(frame1, width=10, height=3, listvariable=var, font=font, yscrollcommand=vsb1.set)
listbox.pack(side=LEFT)
vsb1.configure(command=listbox.yview)

frame2 = Frame(root)
frame2.pack(side=LEFT, fill='y')
combobox = ttk.Combobox(frame2, values=lst, width=10, height=3, font=font)
combobox.pack()

root.mainloop()

enter image description here

Platform

  • WIN10
  • Python 3.9.9 / tkinter 8.6.12, or
  • Python 3.8.10 / tkinter 8.6.9
Jason Yang
  • 11,284
  • 2
  • 9
  • 23
  • Of course, I can see every items if I set height to len(items). My question is to scroll items by mouse wheel in widget I got items indexed 0,1,2 first, then 4,5,6, no item shown for index 3. – Jason Yang Jan 18 '22 at 06:04

1 Answers1

0

enter image description here Same thing happens with pysimplgui, which is what I use. Scrolling seems to be too 'sensitive' for lack of a better word. when you click on the scroll bar and drag it manually you will see that 'Wednesday" does in fact appear in the listbox. I haven't been able to find a fix for it yet but it could be out there

colk84
  • 92
  • 9
  • Yes, I know I can do it by scroll scrollbar of tk.Listbox, or mouse wheel on input of ttk.Combobox. Just question if this issue is a bug or I did it something wrong. The backend of PySimpleGUI is tkinter, of course, they got the same result. – Jason Yang Jan 18 '22 at 06:09
  • @jaso I wasn't sure you were aware. after reading this [post](https://stackoverflow.com/questions/63294204/prevent-tkinter-scrollbar-on-scrollable-frame-from-scrolling-at-2x-speed) it seems you can use a class to modify the scroll strength. I'm going to try it out tomorrow, i'll check back in – colk84 Jan 18 '22 at 06:22
  • I didn't handle the mouse wheel binding by myself, and it is default how tkinter do it, so it maybe an issue about how tkinter work. Of course, it may be solved if I define the bindng by myself. – Jason Yang Jan 18 '22 at 06:35
  • i was able to use the code in that post and make your list scrollable at what ever speed you like. havent been able to figure out how to make the items in that list clickable though for events. since the code doesnt use a listbox but a canvas instead – colk84 Jan 19 '22 at 01:58