From e269091ffe29f885d2f00b387053a88ae421be70 Mon Sep 17 00:00:00 2001 From: TomSchimansky Date: Sat, 12 Nov 2022 13:28:16 +0100 Subject: [PATCH] fixed small bugs, add CTkFiledialog which is tkinter.filedialog --- customtkinter/__init__.py | 4 ++-- customtkinter/windows/ctk_input_dialog.py | 7 +++---- .../widgets/core_widget_classes/widget_base_class.py | 5 ++++- customtkinter/windows/widgets/scaling/scaling_tracker.py | 4 +++- .../{test_askdialog.py => test_filedialog.py} | 0 5 files changed, 12 insertions(+), 8 deletions(-) rename test/manual_integration_tests/{test_askdialog.py => test_filedialog.py} (100%) diff --git a/customtkinter/__init__.py b/customtkinter/__init__.py index 15e95db..357b3ed 100644 --- a/customtkinter/__init__.py +++ b/customtkinter/__init__.py @@ -2,11 +2,11 @@ __version__ = "4.6.3" import os import sys -import tkinter.filedialog as filedialog from tkinter import Variable, StringVar, IntVar, DoubleVar, BooleanVar from tkinter.constants import * +import tkinter.filedialog as CTkFiledialog -_ = filedialog, Variable, StringVar, IntVar, DoubleVar, BooleanVar, CENTER # prevent IDE from removing unused imports +_ = Variable, StringVar, IntVar, DoubleVar, BooleanVar, CENTER, CTkFiledialog # prevent IDE from removing unused imports # import manager classes from .windows.widgets.appearance_mode.appearance_mode_tracker import AppearanceModeTracker diff --git a/customtkinter/windows/ctk_input_dialog.py b/customtkinter/windows/ctk_input_dialog.py index 519d5af..475ffda 100644 --- a/customtkinter/windows/ctk_input_dialog.py +++ b/customtkinter/windows/ctk_input_dialog.py @@ -42,12 +42,11 @@ class CTkInputDialog(CTkToplevel): self._text = text self.title(title) - self.focus_force() self.lift() # lift window on top self.attributes("-topmost", True) # stay on top self.protocol("WM_DELETE_WINDOW", self._on_closing) - self.after(0, self._create_widgets) # create widgets with slight delay, to avoid white flickering of background - self.after(500, lambda: self.resizable(False, False)) + self.after(10, self._create_widgets) # create widgets with slight delay, to avoid white flickering of background + self.resizable(False, False) self.grab_set() # make other windows not clickable def _create_widgets(self): @@ -90,7 +89,7 @@ class CTkInputDialog(CTkToplevel): command=self._ok_event) self._cancel_button.grid(row=2, column=1, columnspan=1, padx=(10, 20), pady=(0, 20), sticky="ew") - self._entry.focus_force() + self.after(150, lambda: self._entry.focus()) # set focus to entry with slight delay, otherwise it won't work self._entry.bind("", self._ok_event) def _ok_event(self, event=None): diff --git a/customtkinter/windows/widgets/core_widget_classes/widget_base_class.py b/customtkinter/windows/widgets/core_widget_classes/widget_base_class.py index 3cb39d7..c3d9220 100644 --- a/customtkinter/windows/widgets/core_widget_classes/widget_base_class.py +++ b/customtkinter/windows/widgets/core_widget_classes/widget_base_class.py @@ -101,7 +101,10 @@ class CTkBaseClass(tkinter.Frame, CTkAppearanceModeBaseClass, CTkScalingBaseClas def _draw(self, no_color_updates: bool = False): """ can be overridden but super method must be called """ if no_color_updates is False: - super().configure(bg=self._apply_appearance_mode(self._bg_color)) + # Configuring color of tkinter.Frame not necessary at the moment? + # Causes flickering on Windows and Linux for segmented button for some reason! + # super().configure(bg=self._apply_appearance_mode(self._bg_color)) + pass def config(self, *args, **kwargs): raise AttributeError("'config' is not implemented for CTk widgets. For consistency, always use 'configure' instead.") diff --git a/customtkinter/windows/widgets/scaling/scaling_tracker.py b/customtkinter/windows/widgets/scaling/scaling_tracker.py index 7ede16f..d5990e0 100644 --- a/customtkinter/windows/widgets/scaling/scaling_tracker.py +++ b/customtkinter/windows/widgets/scaling/scaling_tracker.py @@ -1,3 +1,4 @@ +import ctypes.wintypes import tkinter import sys from typing import Callable @@ -118,7 +119,7 @@ class ScalingTracker: pass # high DPI scaling works automatically on macOS elif sys.platform.startswith("win"): - from ctypes import windll + from ctypes import windll, wintypes windll.shcore.SetProcessDpiAwareness(2) # Microsoft Docs: https://docs.microsoft.com/en-us/windows/win32/api/shellscalingapi/ne-shellscalingapi-process_dpi_awareness else: @@ -154,6 +155,7 @@ class ScalingTracker: for window in cls.window_widgets_dict: if window.winfo_exists() and not window.state() == "iconic": current_dpi_scaling_value = cls.get_window_dpi_scaling(window) + print("current dpi:", current_dpi_scaling_value) if current_dpi_scaling_value != cls.window_dpi_scaling_dict[window]: cls.window_dpi_scaling_dict[window] = current_dpi_scaling_value diff --git a/test/manual_integration_tests/test_askdialog.py b/test/manual_integration_tests/test_filedialog.py similarity index 100% rename from test/manual_integration_tests/test_askdialog.py rename to test/manual_integration_tests/test_filedialog.py