python / cpython

The Python programming language
https://www.python.org
Other
63.53k stars 30.44k forks source link

Item not shown when using mouse wheel to scroll for Listbox/Combobox #90959

Open f8623e57-511d-4cca-9518-88120e657c88 opened 2 years ago

f8623e57-511d-4cca-9518-88120e657c88 commented 2 years ago
BPO 46803
Nosy @stevendaprano, @Jason990420
Files
  • PeS9r.png: Screeeshot
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields: ```python assignee = None closed_at = None created_at = labels = ['3.8', 'type-bug', 'expert-tkinter', '3.9'] title = 'Item not shown when using mouse wheel to scroll for Listbox/Combobox' updated_at = user = 'https://github.com/Jason990420' ``` bugs.python.org fields: ```python activity = actor = 'steven.daprano' assignee = 'none' closed = False closed_date = None closer = None components = ['Tkinter'] creation = creator = 'Jason990420' dependencies = [] files = ['50634'] hgrepos = [] issue_num = 46803 keywords = [] message_count = 2.0 messages = ['413564', '413565'] nosy_count = 2.0 nosy_names = ['steven.daprano', 'Jason990420'] pr_nums = [] priority = 'normal' resolution = None stage = None status = 'open' superseder = None type = 'behavior' url = 'https://bugs.python.org/issue46803' versions = ['Python 3.8', 'Python 3.9'] ```

    f8623e57-511d-4cca-9518-88120e657c88 commented 2 years ago

    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

    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

    stevendaprano commented 2 years ago

    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:

    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.