mirror of
https://github.com/TomSchimansky/CustomTkinter.git
synced 2023-08-10 21:13:13 +03:00
fixed small bugs, add CTkFiledialog which is tkinter.filedialog
This commit is contained in:
parent
f302b045e3
commit
e269091ffe
@ -2,11 +2,11 @@ __version__ = "4.6.3"
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import tkinter.filedialog as filedialog
|
|
||||||
from tkinter import Variable, StringVar, IntVar, DoubleVar, BooleanVar
|
from tkinter import Variable, StringVar, IntVar, DoubleVar, BooleanVar
|
||||||
from tkinter.constants import *
|
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
|
# import manager classes
|
||||||
from .windows.widgets.appearance_mode.appearance_mode_tracker import AppearanceModeTracker
|
from .windows.widgets.appearance_mode.appearance_mode_tracker import AppearanceModeTracker
|
||||||
|
@ -42,12 +42,11 @@ class CTkInputDialog(CTkToplevel):
|
|||||||
self._text = text
|
self._text = text
|
||||||
|
|
||||||
self.title(title)
|
self.title(title)
|
||||||
self.focus_force()
|
|
||||||
self.lift() # lift window on top
|
self.lift() # lift window on top
|
||||||
self.attributes("-topmost", True) # stay on top
|
self.attributes("-topmost", True) # stay on top
|
||||||
self.protocol("WM_DELETE_WINDOW", self._on_closing)
|
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(10, self._create_widgets) # create widgets with slight delay, to avoid white flickering of background
|
||||||
self.after(500, lambda: self.resizable(False, False))
|
self.resizable(False, False)
|
||||||
self.grab_set() # make other windows not clickable
|
self.grab_set() # make other windows not clickable
|
||||||
|
|
||||||
def _create_widgets(self):
|
def _create_widgets(self):
|
||||||
@ -90,7 +89,7 @@ class CTkInputDialog(CTkToplevel):
|
|||||||
command=self._ok_event)
|
command=self._ok_event)
|
||||||
self._cancel_button.grid(row=2, column=1, columnspan=1, padx=(10, 20), pady=(0, 20), sticky="ew")
|
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("<Return>", self._ok_event)
|
self._entry.bind("<Return>", self._ok_event)
|
||||||
|
|
||||||
def _ok_event(self, event=None):
|
def _ok_event(self, event=None):
|
||||||
|
@ -101,7 +101,10 @@ class CTkBaseClass(tkinter.Frame, CTkAppearanceModeBaseClass, CTkScalingBaseClas
|
|||||||
def _draw(self, no_color_updates: bool = False):
|
def _draw(self, no_color_updates: bool = False):
|
||||||
""" can be overridden but super method must be called """
|
""" can be overridden but super method must be called """
|
||||||
if no_color_updates is False:
|
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):
|
def config(self, *args, **kwargs):
|
||||||
raise AttributeError("'config' is not implemented for CTk widgets. For consistency, always use 'configure' instead.")
|
raise AttributeError("'config' is not implemented for CTk widgets. For consistency, always use 'configure' instead.")
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import ctypes.wintypes
|
||||||
import tkinter
|
import tkinter
|
||||||
import sys
|
import sys
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
@ -118,7 +119,7 @@ class ScalingTracker:
|
|||||||
pass # high DPI scaling works automatically on macOS
|
pass # high DPI scaling works automatically on macOS
|
||||||
|
|
||||||
elif sys.platform.startswith("win"):
|
elif sys.platform.startswith("win"):
|
||||||
from ctypes import windll
|
from ctypes import windll, wintypes
|
||||||
windll.shcore.SetProcessDpiAwareness(2)
|
windll.shcore.SetProcessDpiAwareness(2)
|
||||||
# Microsoft Docs: https://docs.microsoft.com/en-us/windows/win32/api/shellscalingapi/ne-shellscalingapi-process_dpi_awareness
|
# Microsoft Docs: https://docs.microsoft.com/en-us/windows/win32/api/shellscalingapi/ne-shellscalingapi-process_dpi_awareness
|
||||||
else:
|
else:
|
||||||
@ -154,6 +155,7 @@ class ScalingTracker:
|
|||||||
for window in cls.window_widgets_dict:
|
for window in cls.window_widgets_dict:
|
||||||
if window.winfo_exists() and not window.state() == "iconic":
|
if window.winfo_exists() and not window.state() == "iconic":
|
||||||
current_dpi_scaling_value = cls.get_window_dpi_scaling(window)
|
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]:
|
if current_dpi_scaling_value != cls.window_dpi_scaling_dict[window]:
|
||||||
cls.window_dpi_scaling_dict[window] = current_dpi_scaling_value
|
cls.window_dpi_scaling_dict[window] = current_dpi_scaling_value
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user