如何修复 Windows 上 WxPython 控件中的模糊文本?

How to fix blurry text in WxPython controls on Windows?

我们有一个基于 Python 的应用程序,它是用 WxPython 4 编写的,我们为多个操作系统构建,包括 Windows。在 Windows 10 中,至少在我的环境中(在高分辨率显示器上的 VM 内),界面中的文本元素是模糊的:

我可以通过 setting the Windows DPI-scaling override 在应用程序上稍微改善这种情况。这是间接的和次优的,似乎应该有一种方法可以从 WxPython 更直接地做到这一点。但是,我还没有找到办法。

是否有任何方法可以从 WxPython 设置 DPI 缩放比例,或者直接从应用程序中修复 WxPython 4 中 Windows 上的模糊文本?

根据 a message from Python Issue Tracker and what I tried in the wxPython official Hello World, Part 2 example (helloworld2.py),将以下代码添加到您的程序应该有效:

import ctypes
try:
    ctypes.windll.shcore.SetProcessDpiAwareness(True)
except:
    pass