This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Item not shown when using mouse wheel to scroll for Listbox/Combobox
Type: behavior Stage:
Components: Tkinter Versions: Python 3.9, Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Jason990420, steven.daprano
Priority: normal Keywords:

Created on 2022-02-20 06:30 by Jason990420, last changed 2022-04-11 14:59 by admin.

Files
File name Uploaded Description Edit
PeS9r.png Jason990420, 2022-02-20 06:30 Screeeshot
Messages (2)
msg413564 - (view) Author: Jason Yang (Jason990420) * Date: 2022-02-20 06:30
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

```python
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()
```

Platform: WIN10
msg413565 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2022-02-20 07:33
Replicated on Linux, Python 3.10.

It looks like mousewheel scrolling jumps by the wrong amount as it pages down (or up), and consequently some lines never appear in the view area.

I ran a slightly modified version of the code that had 16 entries instead of just seven. By default, just three entries are visible at a time. If we number the lines 1-16, and start with lines 1-3 visible, then we get:

* Initial view: lines 1, 2, 3 visible, 4-16 below the view area.
* Scrollwheel down.
* Lines 6-8 visible, 1-5 above the view area, 9-16 below.
* Scrollwheel down.
* Lines 11-13 visible, 1-10 above the view area, 14-16 below.
* Scrollwheel down.
* Lines 14-16 visible, 1-13 above the view area.

So the scrollwheel scrolls down by: 5 lines, 5 lines, 3 lines.

Going back the otherway, the scrollwheel scrolls up by 5, 5, 3.

Why five lines? My guess is that it might have something to do with 16//3 = 5.

I don't know if this is something we can fix, or we're stuck with whatever tk/tcl does.

I don't know if this is related, or should be a separate issue, but I see that the keyboard PageUp and PageDown keys don't scroll up or down by a page, but by a single line -- and they don't correctly highlight the selected line either.

Paging should scroll up or down by N-1 lines, where N is the number of visible lines in the view area.

Likewise for clicking in the scrollbar's PageUp/PageDown region, which also scrolls by a single line.
History
Date User Action Args
2022-04-11 14:59:56adminsetgithub: 90959
2022-02-20 08:58:44steven.dapranosetfiles: - 6.jpeg
2022-02-20 08:58:03steven.dapranosetnosy: - xiaox55066
2022-02-20 08:57:47steven.dapranosetmessages: - msg413568
2022-02-20 08:57:30steven.dapranosetmessages: - msg413567
2022-02-20 08:57:09steven.dapranosetmessages: - msg413566
2022-02-20 08:37:01xiaox55066setmessages: + msg413568
2022-02-20 08:36:05xiaox55066setmessages: + msg413567
2022-02-20 08:35:08xiaox55066setfiles: + 6.jpeg
nosy: + xiaox55066
messages: + msg413566

2022-02-20 07:33:42steven.dapranosetnosy: + steven.daprano
messages: + msg413565
2022-02-20 06:30:30Jason990420create