CustomTkinter icon indicating copy to clipboard operation
CustomTkinter copied to clipboard

Mouse wheel doesn't work on ScrollableFrame

Open jedediahfanuel opened this issue 1 year ago • 9 comments

I tried scrollable_frame_example.py on linux machine (endeavour os), the mouse wheel doesn't work if i scroll the frame. But, i tried it on windows machine (windows 10), it works perfectly.

jedediahfanuel avatar Mar 17 '23 04:03 jedediahfanuel

Probably a bug in the mouse-wheel binding of CTkScrollableFrame. In windows, the mouse-wheel is binded using <MouseWheel> method, but for linux machine the mouse-wheel binding is <Button-4> for up scroll and <Button-5> for down scroll (which is currently not implemented).

For now, you can fix this by adding those bindings in your scroll frame:

scroll_frame = customtkinter.CTkScrollableFrame(root)
scroll_frame.bind_all("<Button-4>", lambda e: scroll_frame._parent_canvas.yview("scroll", -1, "units"))
scroll_frame.bind_all("<Button-5>", lambda e: scroll_frame._parent_canvas.yview("scroll", 1, "units"))

@TomSchimansky, please add those binding and improve this function inside ctk_scrollable_frame.py.

Akascape avatar Mar 17 '23 16:03 Akascape

Just a word of warning. I tested the above solution, and if you have another scrollable widget in the frame, it is susceptible to the scrolling being concurrently activated. When you scroll the 2nd widget (I used CTkTextbox), it also causes scrolling of the CTkScrollableFrame.

avalon60 avatar Apr 25 '23 23:04 avalon60

This is still an issue for me.

yuckdevchan avatar Oct 28 '23 19:10 yuckdevchan

Us moment bro

Gabbar-v7 avatar Nov 18 '23 09:11 Gabbar-v7

Just a word of warning. I tested the above solution, and if you have another scrollable widget in the frame, it is susceptible to the scrolling being concurrently activated. When you scroll the 2nd widget (I used CTkTextbox), it also causes scrolling of the CTkScrollableFrame.

bro that code has a bug instead of .bind_all() use .bind()

Gabbar-v7 avatar Nov 18 '23 09:11 Gabbar-v7

will the scroll function still work on windows if I make those adjustments for my linux and package it later?

DevInfinix avatar Feb 08 '24 15:02 DevInfinix

will the scroll function still work on windows if I make those adjustments for my linux and package it later?

If u are asking me then yes it will work on windows as well it wont create any issue. Simulaneously it will also work on linux I have tried on both Os. Just checkout the pr that i have added on top PR #2089

Gabbar-v7 avatar Feb 08 '24 15:02 Gabbar-v7

Just a word of warning. I tested the above solution, and if you have another scrollable widget in the frame, it is susceptible to the scrolling being concurrently activated. When you scroll the 2nd widget (I used CTkTextbox), it also causes scrolling of the CTkScrollableFrame.

Yeah, unfortunately bind_all fires off regardless of which frame you scroll in for me. This is the current solution in my TabView:

        self.settings_frame = SettingsFrame(self.tab("Settings"))
        self.settings_frame.pack(expand=True, fill='both')

        self.stats_frame = StatsFrame(self.tab("Stats"))
        self.stats_frame.pack(expand=True, fill='both')

        self.stats_frame.bind_all("<Button-4>", lambda e: [frame._parent_canvas.yview("scroll", -1, "units") for frame in (self.stats_frame, self.settings_frame)])
        self.stats_frame.bind_all("<Button-5>", lambda e: [frame._parent_canvas.yview("scroll", 1, "units") for frame in (self.stats_frame, self.settings_frame)])

jake158 avatar Apr 05 '24 17:04 jake158

will the scroll function still work on windows if I make those adjustments for my linux and package it later?

If u are asking me then yes it will work on windows as well it wont create any issue. Simulaneously it will also work on linux I have tried on both Os. Just checkout the pr that i have added on top PR #2089

Hi @Gabbar-v7. I haven't been able to create a PR, since Github mandated 2FA. Any tips on how I go about this?

avalon60 avatar Apr 07 '24 10:04 avalon60