fixed assets font path

This commit is contained in:
TomSchimansky 2022-11-30 21:51:36 +01:00
parent bfbe4a4e5c
commit 50a8bb140e
4 changed files with 13 additions and 15 deletions

View File

@ -13,7 +13,3 @@ from .ctk_slider import CTkSlider
from .ctk_switch import CTkSwitch from .ctk_switch import CTkSwitch
from .ctk_tabview import CTkTabview from .ctk_tabview import CTkTabview
from .ctk_textbox import CTkTextbox from .ctk_textbox import CTkTextbox
# init canvas font character map for current platform
from .core_rendering import CTkCanvas
CTkCanvas.init_font_character_mapping()

View File

@ -3,6 +3,8 @@ import sys
from .ctk_canvas import CTkCanvas from .ctk_canvas import CTkCanvas
from .draw_engine import DrawEngine from .draw_engine import DrawEngine
CTkCanvas.init_font_character_mapping()
# determine draw method based on current platform # determine draw method based on current platform
if sys.platform == "darwin": if sys.platform == "darwin":
DrawEngine.preferred_drawing_method = "polygon_shapes" DrawEngine.preferred_drawing_method = "polygon_shapes"

View File

@ -10,15 +10,15 @@ from ..core_rendering import DrawEngine
FontManager.init_font_manager() FontManager.init_font_manager()
# load Roboto fonts (used on Windows/Linux) # load Roboto fonts (used on Windows/Linux)
script_directory = os.path.dirname(os.path.abspath(__file__)) customtkinter_directory = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
FontManager.load_font(os.path.join(script_directory, "assets", "fonts", "Roboto", "Roboto-Regular.ttf")) FontManager.load_font(os.path.join(customtkinter_directory, "assets", "fonts", "Roboto", "Roboto-Regular.ttf"))
FontManager.load_font(os.path.join(script_directory, "assets", "fonts", "Roboto", "Roboto-Medium.ttf")) FontManager.load_font(os.path.join(customtkinter_directory, "assets", "fonts", "Roboto", "Roboto-Medium.ttf"))
# load font necessary for rendering the widgets (used on Windows/Linux) # load font necessary for rendering the widgets (used on Windows/Linux)
if FontManager.load_font(os.path.join(script_directory, "assets", "fonts", "CustomTkinter_shapes_font.otf")) is False: if FontManager.load_font(os.path.join(customtkinter_directory, "assets", "fonts", "CustomTkinter_shapes_font.otf")) is False:
# change draw method if font loading failed # change draw method if font loading failed
if DrawEngine.preferred_drawing_method == "font_shapes": if DrawEngine.preferred_drawing_method == "font_shapes":
sys.stderr.write("customtkinter.__init__ warning: " + sys.stderr.write("customtkinter.windows.widgets.font warning: " +
"Preferred drawing method 'font_shapes' can not be used because the font file could not be loaded.\n" + "Preferred drawing method 'font_shapes' can not be used because the font file could not be loaded.\n" +
"Using 'circle_shapes' instead. The rendering quality will be bad!\n") "Using 'circle_shapes' instead. The rendering quality will be bad!\n")
DrawEngine.preferred_drawing_method = "circle_shapes" DrawEngine.preferred_drawing_method = "circle_shapes"

View File

@ -16,12 +16,12 @@ class App(customtkinter.CTk):
# load images with light and dark mode image # load images with light and dark mode image
current_path = os.path.dirname(os.path.realpath(__file__)) current_path = os.path.dirname(os.path.realpath(__file__))
self.home_image = customtkinter.CTkImage(light_image=Image.open(current_path + "/test_images/home_dark.png"), self.home_image = customtkinter.CTkImage(light_image=Image.open(os.path.join(current_path, "test_images", "home_dark.png")),
dark_image=Image.open(current_path + "/test_images/home_light.png"), size=(20, 20)) dark_image=Image.open(os.path.join(current_path, "test_images", "home_light.png")), size=(20, 20))
self.chat_image = customtkinter.CTkImage(light_image=Image.open(current_path + "/test_images/chat_dark.png"), self.chat_image = customtkinter.CTkImage(light_image=Image.open(os.path.join(current_path, "test_images", "chat_dark.png")),
dark_image=Image.open(current_path + "/test_images/chat_light.png"), size=(20, 20)) dark_image=Image.open(os.path.join(current_path, "test_images", "chat_light.png")), size=(20, 20))
self.add_user_image = customtkinter.CTkImage(light_image=Image.open(current_path + "/test_images/add_user_dark.png"), self.add_user_image = customtkinter.CTkImage(light_image=Image.open(os.path.join(current_path, "test_images", "add_user_dark.png")),
dark_image=Image.open(current_path + "/test_images/add_user_light.png"), size=(20, 20)) dark_image=Image.open(os.path.join(current_path, "test_images", "add_user_light.png")), size=(20, 20))
# create navigation frame # create navigation frame
self.navigation_frame = customtkinter.CTkFrame(self, corner_radius=0) self.navigation_frame = customtkinter.CTkFrame(self, corner_radius=0)