changed scrollbar colors, added custom exception message for pyinstaller file problem

This commit is contained in:
Tom Schimansky 2022-06-20 23:44:35 +02:00
parent 43900c7fef
commit a7b175ae65
7 changed files with 58 additions and 34 deletions

View File

@ -14,7 +14,15 @@ from .font_manager import FontManager
from .draw_engine import DrawEngine
AppearanceModeTracker.init_appearance_mode()
ThemeManager.load_theme("blue") # load default theme
# load default blue theme
try:
ThemeManager.load_theme("blue")
except FileNotFoundError as err:
raise FileNotFoundError(f"{err}\n\nThe .json theme file for CustomTkinter could not be found.\n" +
f"If packaging with pyinstaller was used, have a look at the wiki:\n" +
f"https://github.com/TomSchimansky/CustomTkinter/wiki/Packaging#windows-pyinstaller-auto-py-to-exe")
FontManager.init_font_manager()
# determine draw method based on current platform

View File

@ -11,7 +11,7 @@
"entry_placeholder_text": ["gray52", "gray62"],
"frame_border": ["#979DA2", "#1F2122"],
"frame_low": ["#D1D5D8", "#2A2D2E"],
"frame_high": ["#D7D8D9", "#343638"],
"frame_high": ["#C0C2C5", "#343638"],
"label": [null, null],
"text": ["gray10", "#DCE4EE"],
"text_disabled": ["gray60", "#777B80"],
@ -34,8 +34,8 @@
"dropdown_color": ["gray90", "gray20"],
"dropdown_hover": ["gray75", "gray28"],
"dropdown_text": ["gray10", "#DCE4EE"],
"scrollbar": ["gray60", "gray38"],
"scrollbar_hover": ["gray45", "gray50"]
"scrollbar_button": ["gray55", "gray41"],
"scrollbar_button_hover": ["gray40", "gray53"]
},
"text": {
"macOS": {

View File

@ -33,7 +33,9 @@
"combobox_button_hover": ["#6E7174", "#7A848D"],
"dropdown_color": ["gray90", "gray20"],
"dropdown_hover": ["gray75", "gray28"],
"dropdown_text": ["gray10", "#DCE4EE"]
"dropdown_text": ["gray10", "#DCE4EE"],
"scrollbar_button": ["gray55", "gray41"],
"scrollbar_button_hover": ["gray40", "gray53"]
},
"text": {
"macOS": {

View File

@ -33,7 +33,9 @@
"combobox_button_hover": ["#6E7174", "#7A848D"],
"dropdown_color": ["gray90", "gray20"],
"dropdown_hover": ["gray75", "gray28"],
"dropdown_text": ["gray10", "#DCE4EE"]
"dropdown_text": ["gray10", "#DCE4EE"],
"scrollbar_button": ["gray55", "gray41"],
"scrollbar_button_hover": ["gray40", "gray53"]
},
"text": {
"macOS": {

View File

@ -33,7 +33,9 @@
"combobox_button_hover": ["#6E7174", "#7A848D"],
"dropdown_color": ["gray90", "gray20"],
"dropdown_hover": ["gray75", "gray28"],
"dropdown_text": ["gray10", "#DCE4EE"]
"dropdown_text": ["gray10", "#DCE4EE"],
"scrollbar_button": ["gray55", "gray41"],
"scrollbar_button_hover": ["gray40", "gray53"]
},
"text": {
"macOS": {

View File

@ -1,5 +1,7 @@
import sys
import tkinter
from .ctk_frame import CTkFrame
from .ctk_canvas import CTkCanvas
from ..theme_manager import ThemeManager
from ..draw_engine import DrawEngine
@ -9,7 +11,7 @@ from .widget_base_class import CTkBaseClass
class CTkScrollbar(CTkBaseClass):
def __init__(self, *args,
bg_color=None,
fg_color=None,
fg_color="default_theme",
scrollbar_color="default_theme",
scrollbar_hover_color="default_theme",
border_spacing="default_theme",
@ -37,9 +39,9 @@ class CTkScrollbar(CTkBaseClass):
super().__init__(*args, bg_color=bg_color, width=width, height=height, **kwargs)
# color
self.fg_color = fg_color
self.scrollbar_color = ThemeManager.theme["color"]["scrollbar"] if scrollbar_color == "default_theme" else scrollbar_color
self.scrollbar_hover_color = ThemeManager.theme["color"]["scrollbar_hover"] if scrollbar_hover_color == "default_theme" else scrollbar_hover_color
self.fg_color = ThemeManager.theme["color"]["frame_high"] if fg_color == "default_theme" else fg_color
self.scrollbar_color = ThemeManager.theme["color"]["scrollbar_button"] if scrollbar_color == "default_theme" else scrollbar_color
self.scrollbar_hover_color = ThemeManager.theme["color"]["scrollbar_button_hover"] if scrollbar_hover_color == "default_theme" else scrollbar_hover_color
# shape
self.corner_radius = ThemeManager.theme["shape"]["scrollbar_corner_radius"] if corner_radius == "default_theme" else corner_radius
@ -57,7 +59,6 @@ class CTkScrollbar(CTkBaseClass):
width=self.apply_widget_scaling(self._current_width),
height=self.apply_widget_scaling(self._current_height))
self.canvas.place(x=0, y=0, relwidth=1, relheight=1)
self.canvas.configure(bg="green")
self.draw_engine = DrawEngine(self.canvas)
self.canvas.bind("<Enter>", self.on_enter)
@ -109,6 +110,8 @@ class CTkScrollbar(CTkBaseClass):
fill=ThemeManager.single_color(self.fg_color, self._appearance_mode),
outline=ThemeManager.single_color(self.fg_color, self._appearance_mode))
self.canvas.update_idletasks()
def set(self, start_value: float, end_value: float):
self.start_value = float(start_value)
self.end_value = float(end_value)

View File

@ -8,35 +8,42 @@ import customtkinter
customtkinter.set_appearance_mode("light")
def to_scollbar(*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(*args)
def from_scrollbar(*args, **kwargs):
tk_textbox.yview(*args, **kwargs)
#print(*args)
app = customtkinter.CTk()
app.grid_rowconfigure(0, weight=1)
app.grid_columnconfigure(0, weight=1)
app.grid_columnconfigure((0, 2), weight=1)
tk_textbox = tkinter.Text(app)
tk_textbox.grid(row=0, column=0, sticky="ns")
ctk_textbox_scrollbar = customtkinter.CTkScrollbar(app, command=from_scrollbar)
tk_textbox = tkinter.Text(app, highlightthickness=0, padx=5, pady=5)
tk_textbox.grid(row=0, column=0, sticky="nsew")
ctk_textbox_scrollbar = customtkinter.CTkScrollbar(app, command=tk_textbox.yview)
ctk_textbox_scrollbar.grid(row=0, column=1, padx=0, sticky="ns")
tk_textbox.configure(yscrollcommand=ctk_textbox_scrollbar.set)
#tk_textbox_scrollbar = tkinter.Scrollbar(app, command=from_scrollbar)
#tk_textbox_scrollbar.grid(row=0, column=2, padx=1, sticky="ns")
frame_1 = customtkinter.CTkFrame(app)
frame_1.grid(row=0, column=2, padx=10, pady=10, sticky="nsew")
frame_1.grid_rowconfigure((0, 1), weight=1)
frame_1.grid_columnconfigure((0, ), weight=1)
tk_textbox_1 = tkinter.Text(frame_1, highlightthickness=0, padx=5, pady=5)
tk_textbox_1.grid(row=0, column=0, sticky="nsew", padx=(5, 0), pady=5)
ctk_textbox_scrollbar_1 = customtkinter.CTkScrollbar(frame_1, command=tk_textbox_1.yview)
ctk_textbox_scrollbar_1.grid(row=0, column=1, sticky="ns", padx=(0, 5), pady=5)
tk_textbox_1.configure(yscrollcommand=ctk_textbox_scrollbar_1.set)
tk_textbox.configure(yscrollcommand=to_scollbar)
frame_2 = customtkinter.CTkFrame(frame_1)
frame_2.grid(row=1, column=0, columnspan=2, padx=20, pady=20, sticky="nsew")
frame_2.grid_rowconfigure((0, 1), weight=1)
frame_2.grid_columnconfigure((0, ), weight=1)
tk_textbox_2 = tkinter.Text(frame_2, highlightthickness=0, padx=5, pady=5)
tk_textbox_2.grid(row=0, column=0, sticky="nsew", padx=(5, 0), pady=5)
ctk_textbox_scrollbar_2 = customtkinter.CTkScrollbar(frame_2, command=tk_textbox_2.yview)
ctk_textbox_scrollbar_2.grid(row=0, column=1, sticky="ns", padx=(0, 5), pady=5)
tk_textbox_2.configure(yscrollcommand=ctk_textbox_scrollbar_2.set)
tk_textbox.configure(font=(customtkinter.ThemeManager.theme["text"]["font"], customtkinter.ThemeManager.theme["text"]["size"]))
tk_textbox_1.configure(font=(customtkinter.ThemeManager.theme["text"]["font"], customtkinter.ThemeManager.theme["text"]["size"]))
tk_textbox_2.configure(font=(customtkinter.ThemeManager.theme["text"]["font"], customtkinter.ThemeManager.theme["text"]["size"]))
tk_textbox.insert("insert", "\n".join([str(i) for i in range(100)]))
tk_textbox_1.insert("insert", "\n".join([str(i) for i in range(1000)]))
tk_textbox_2.insert("insert", "\n".join([str(i) for i in range(10000)]))
app.mainloop()