diff --git a/Lib/idlelib/pyshell.py b/Lib/idlelib/pyshell.py index d8b2652d5d7979..d46b54687d52e9 100755 --- a/Lib/idlelib/pyshell.py +++ b/Lib/idlelib/pyshell.py @@ -11,10 +11,6 @@ "Your Python may not be configured for Tk. **", file=sys.__stderr__) raise SystemExit(1) -if sys.platform == 'win32': - from idlelib.util import fix_win_hidpi - fix_win_hidpi() - from tkinter import messagebox from code import InteractiveInterpreter diff --git a/Lib/idlelib/util.py b/Lib/idlelib/util.py index e05604ab4853f6..6f55bfae919d28 100644 --- a/Lib/idlelib/util.py +++ b/Lib/idlelib/util.py @@ -12,26 +12,11 @@ * std streams (pyshell, run), * warning stuff (pyshell, run). """ -import sys - # .pyw is for Windows; .pyi is for typing stub files. # The extension order is needed for iomenu open/save dialogs. py_extensions = ('.py', '.pyw', '.pyi') -# Fix for HiDPI screens on Windows. CALL BEFORE ANY TK OPERATIONS! -# URL for arguments for the ...Awareness call below. -# https://msdn.microsoft.com/en-us/library/windows/desktop/dn280512(v=vs.85).aspx -if sys.platform == 'win32': # pragma: no cover - def fix_win_hidpi(): # Called in pyshell and turtledemo. - try: - import ctypes - PROCESS_SYSTEM_DPI_AWARE = 1 # Int required. - ctypes.OleDLL('shcore').SetProcessDpiAwareness(PROCESS_SYSTEM_DPI_AWARE) - except (ImportError, AttributeError, OSError): - pass - - if __name__ == '__main__': from unittest import main main('idlelib.idle_test.test_util', verbosity=2) diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py index 5352276e874bf5..977c53e06dc424 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -2496,6 +2496,26 @@ def _loadtk(self): _default_root = self self.protocol("WM_DELETE_WINDOW", self.destroy) + # Fix for HiDPI screens on Windows + # CALL BEFORE ANY TK OPERATIONS! + # URL for arguments for the ...Awareness call below. + # https://msdn.microsoft.com/en-us/library/windows/desktop/dn280512(v=vs.85).aspx + if sys.platform == 'win32': + import ctypes + try: + ctypes.windll.user32.SetProcessDPIAware() + # >= win 8.1 required + # Ensures that the window size is not reduced due to DPI adjustments, + # maintaining the original size + ScaleFactor = ctypes.windll.shcore.GetScaleFactorForDevice(0) + self.tk.call('tk', 'scaling', ScaleFactor / 75) + except (ImportError, AttributeError, OSError): + # <= win 8 + try: + ctypes.windll.user32.SetProcessDPIAware() + except (ImportError, AttributeError, OSError): + pass + def destroy(self): """Destroy this and all descendants widgets. This will end the application of this Tcl interpreter.""" diff --git a/Lib/turtledemo/__main__.py b/Lib/turtledemo/__main__.py index 06a64081a896b5..49bf562dcc9e1d 100644 --- a/Lib/turtledemo/__main__.py +++ b/Lib/turtledemo/__main__.py @@ -93,10 +93,6 @@ import turtle from turtledemo import __doc__ as about_turtledemo -if sys.platform == 'win32': - from idlelib.util import fix_win_hidpi - fix_win_hidpi() - demo_dir = os.path.dirname(os.path.abspath(__file__)) darwin = sys.platform == 'darwin' STARTUP = 1 diff --git a/Misc/NEWS.d/next/Library/2024-06-01-19-07-55.gh-issue-119459.WRP-4n.rst b/Misc/NEWS.d/next/Library/2024-06-01-19-07-55.gh-issue-119459.WRP-4n.rst new file mode 100644 index 00000000000000..61d0096871c4bb --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-06-01-19-07-55.gh-issue-119459.WRP-4n.rst @@ -0,0 +1,2 @@ +Fix HiDPI blurring of every program window that using tkinter. Patch by +Wulian233