diff --git a/customtkinter/__init__.py b/customtkinter/__init__.py index 956e803..379e22a 100644 --- a/customtkinter/__init__.py +++ b/customtkinter/__init__.py @@ -19,7 +19,6 @@ from distutils.version import StrictVersion as Version import tkinter import os import sys -from ctypes import windll, byref, create_unicode_buffer, create_string_buffer def enable_macos_darkmode(): @@ -62,18 +61,21 @@ def set_default_color_theme(color_string): CTkColorManager.initialize_color_theme(color_string) -FR_PRIVATE = 0x10 -FR_NOT_ENUM = 0x20 +if sys.platform.startswith("win"): + from ctypes import windll, byref, create_string_buffer + + FR_PRIVATE = 0x10 + FR_NOT_ENUM = 0x20 -def loadfont(fontpath: str, private=True, enumerable=False): - pathbuf = create_string_buffer(bytes(fontpath, "utf-8")) - add_font_resource_ex = windll.gdi32.AddFontResourceExA - flags = (FR_PRIVATE if private else 0) | (FR_NOT_ENUM if not enumerable else 0) - num_fonts_added = add_font_resource_ex(byref(pathbuf), flags, 0) - return bool(num_fonts_added) + def loadfont(fontpath: str, private=True, enumerable=False): + pathbuf = create_string_buffer(bytes(fontpath, "utf-8")) + add_font_resource_ex = windll.gdi32.AddFontResourceExA + flags = (FR_PRIVATE if private else 0) | (FR_NOT_ENUM if not enumerable else 0) + num_fonts_added = add_font_resource_ex(byref(pathbuf), flags, 0) + return bool(num_fonts_added) -# load custom font for rendering circles on the tkinter.Canvas with antialiasing -script_directory = os.path.dirname(os.path.abspath(__file__)) -loadfont(os.path.join(script_directory, "assets", "canvas_shapes_font.otf"), private=True) + # load custom font for rendering circles on the tkinter.Canvas with antialiasing + script_directory = os.path.dirname(os.path.abspath(__file__)) + loadfont(os.path.join(script_directory, "assets", "canvas_shapes_font.otf"), private=True) diff --git a/customtkinter/customtkinter_dialog.py b/customtkinter/customtkinter_dialog.py index 088d3c4..e420e96 100644 --- a/customtkinter/customtkinter_dialog.py +++ b/customtkinter/customtkinter_dialog.py @@ -45,6 +45,7 @@ class CTkDialog: self.myLabel = CTkLabel(master=self.label_frame, text=text, width=300, + fg_color=None, height=self.height-100) self.myLabel.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER) @@ -68,7 +69,10 @@ class CTkDialog: hover_color=self.hover_color) self.cancel_button.place(relx=0.72, rely=0.65, anchor=tkinter.CENTER) - def ok_event(self): + self.entry.entry.focus_force() + self.entry.bind("", self.ok_event) + + def ok_event(self, event=None): self.user_input = self.entry.get() self.running = False @@ -89,14 +93,13 @@ class CTkDialog: if __name__ == "__main__": import customtkinter - customtkinter.enable_macos_darkmode() customtkinter.set_appearance_mode("System") - app = tkinter.Tk() + app = customtkinter.CTk() app.title("CTkDialog Test") def button_click_event(): - dialog = CTkDialog(master=None, text="Type in a number:", title="Test", fg_color="green", hover_color="darkgreen") + dialog = CTkDialog(master=None, text="Type in a number:", title="Test") print("Number:", dialog.get_input()) button = CTkButton(master=app, text="Open Dialog", command=button_click_event) diff --git a/customtkinter/customtkinter_tk.py b/customtkinter/customtkinter_tk.py index 1363bab..d7419d2 100644 --- a/customtkinter/customtkinter_tk.py +++ b/customtkinter/customtkinter_tk.py @@ -4,7 +4,6 @@ import sys import os import platform import ctypes -import win32con from .appearance_mode_tracker import AppearanceModeTracker from .customtkinter_color_manager import CTkColorManager