fixed scrollbar for Windows

This commit is contained in:
TomSchimansky 2022-06-19 22:12:19 +02:00
parent 79ecd2e946
commit 43900c7fef
4 changed files with 26 additions and 16 deletions

View File

@ -34,8 +34,8 @@
"dropdown_color": ["gray90", "gray20"],
"dropdown_hover": ["gray75", "gray28"],
"dropdown_text": ["gray10", "#DCE4EE"],
"scrollbar": ["gray75", "gray25"],
"scrollbar_hover": ["gray50", "gray40"]
"scrollbar": ["gray60", "gray38"],
"scrollbar_hover": ["gray45", "gray50"]
},
"text": {
"macOS": {
@ -73,7 +73,7 @@
"switch_corner_radius": 1000,
"switch_button_corner_radius": 1000,
"switch_button_length": 0,
"scrollbar_corner_radius": 6,
"scrollbar_corner_radius": 1000,
"scrollbar_border_spacing": 4
}
}

View File

@ -1062,16 +1062,16 @@ class DrawEngine:
else:
self._canvas.delete("scrollbar_corner_part")
if not self._canvas.find_withtag("scrollbar_rectangle_1") and width > 2 * corner_radius:
if not self._canvas.find_withtag("scrollbar_rectangle_1") and height > 2 * corner_radius:
self._canvas.create_rectangle(0, 0, 0, 0, tags=("scrollbar_rectangle_1", "scrollbar_rectangle_part", "scrollbar_parts"), width=0)
requires_recoloring = True
elif self._canvas.find_withtag("scrollbar_rectangle_1") and not width > 2 * corner_radius:
elif self._canvas.find_withtag("scrollbar_rectangle_1") and not height > 2 * corner_radius:
self._canvas.delete("scrollbar_rectangle_1")
if not self._canvas.find_withtag("scrollbar_rectangle_2"):
if not self._canvas.find_withtag("scrollbar_rectangle_2") and width > 2 * corner_radius:
self._canvas.create_rectangle(0, 0, 0, 0, tags=("scrollbar_rectangle_2", "scrollbar_rectangle_part", "scrollbar_parts"), width=0)
requires_recoloring = True
elif self._canvas.find_withtag("scrollbar_rectangle_2") and not height > 2 * corner_radius:
elif self._canvas.find_withtag("scrollbar_rectangle_2") and not width > 2 * corner_radius:
self._canvas.delete("scrollbar_rectangle_2")
self._canvas.coords("scrollbar_rectangle_1",

View File

@ -1,3 +1,5 @@
import sys
from .ctk_canvas import CTkCanvas
from ..theme_manager import ThemeManager
from ..draw_engine import DrawEngine
@ -196,5 +198,8 @@ class CTkScrollbar(CTkBaseClass):
def mouse_scroll_event(self, event=None):
if self.command is not None:
self.command('scroll', event.delta, 'units')
if sys.platform.startswith("win"):
self.command('scroll', -int(event.delta/40), 'units')
else:
self.command('scroll', -event.delta, 'units')

View File

@ -2,19 +2,24 @@ import tkinter
import customtkinter
# customtkinter.DrawEngine.preferred_drawing_method = "font_shapes"
#customtkinter.set_widget_scaling(2)
#customtkinter.set_window_scaling(2)
#customtkinter.set_spacing_scaling(2)
customtkinter.set_appearance_mode("light")
def to_scollbar(*args, **kwargs):
tk_textbox_scrollbar.set(*args, **kwargs)
#tk_textbox_scrollbar.set(*args, **kwargs)
ctk_textbox_scrollbar.set(*args, **kwargs)
ctk_textbox_scrollbar.update_idletasks()
tk_textbox_scrollbar.update_idletasks()
print("to_scollbar:", args, **kwargs)
#tk_textbox_scrollbar.update_idletasks()
#print(*args)
def from_scrollbar(*args, **kwargs):
tk_textbox.yview(*args, **kwargs)
print("from_scrollbar:", args, **kwargs)
#print(*args)
app = customtkinter.CTk()
@ -22,13 +27,13 @@ app.grid_rowconfigure(0, weight=1)
app.grid_columnconfigure(0, weight=1)
tk_textbox = tkinter.Text(app)
tk_textbox.grid(row=0, column=0, sticky="nsew")
tk_textbox.grid(row=0, column=0, sticky="ns")
ctk_textbox_scrollbar = customtkinter.CTkScrollbar(app, command=from_scrollbar, fg_color="red")
ctk_textbox_scrollbar = customtkinter.CTkScrollbar(app, command=from_scrollbar)
ctk_textbox_scrollbar.grid(row=0, column=1, padx=0, sticky="ns")
tk_textbox_scrollbar = tkinter.Scrollbar(app, command=from_scrollbar)
tk_textbox_scrollbar.grid(row=0, column=2, padx=1, sticky="ns")
#tk_textbox_scrollbar = tkinter.Scrollbar(app, command=from_scrollbar)
#tk_textbox_scrollbar.grid(row=0, column=2, padx=1, sticky="ns")
tk_textbox.configure(yscrollcommand=to_scollbar)