Skip to main content

Fix blurry Tkinter applications on Windows 10/11 high-DPI displays

Project description

tkinter-unblur

PyPI version Python versions

Type checked CI License

Note: hdpitkinter has been reborn as tkinter-unblur with modern features. See migration guide.

Fix blurry Tkinter applications on Windows 10/11 high-DPI displays.

The Problem

Tkinter applications look blurry and pixelated on modern high-resolution displays with scaling enabled (125%, 150%, 200%, etc.). This is because Tkinter is not DPI-aware by default on Windows.

The Solution

# Before (blurry)
from tkinter import Tk

# After (crystal clear)
from tkinter_unblur import Tk

That's it. One import change, and your Tkinter app renders sharply.

Visual Comparison

Blurry vs Sharp Comparison

Left: Standard Tkinter (blurry) | Right: tkinter-unblur (sharp)

Installation

pip install tkinter-unblur

Usage

from tkinter_unblur import Tk

root = Tk()
root.title("My App")
root.geometry("800x600")
root.mainloop()

That's all you need! For advanced usage, see API Reference.

API Reference

Tk Class

A drop-in replacement for tkinter.Tk with DPI awareness.

Attributes

  • dpi_x: int | None - Horizontal DPI (96 = 100% scaling)
  • dpi_y: int | None - Vertical DPI (96 = 100% scaling)
  • dpi_scaling: float - Scaling factor (1.0 = 100%, 1.5 = 150%)

Example:

root = Tk()
print(f"DPI: {root.dpi_x}x{root.dpi_y}")
print(f"Scaling: {root.dpi_scaling:.0%}")  # e.g., "Scaling: 150%"

Methods

scale_value(value: int) -> int

Scale a numeric value by the DPI factor.

Example:

from tkinter import Label

root = Tk()
# Scale font size to maintain physical size across different DPI settings
label = Label(root, text="Hello", font=("Arial", root.scale_value(12)))
scale_geometry(geometry: str) -> str

Scale a geometry string ("WxH+X+Y") by the DPI factor.

Example:

root = Tk()
# Scale window geometry (width x height + x + y)
root.geometry(root.scale_geometry("800x600+100+50"))

Exceptions

  • TkinterUnblurError - Base exception
  • UnsupportedPlatformError - Platform doesn't support DPI awareness
  • DPIDetectionError - DPI detection failed

How It Works

On Windows, this library:

  1. Calls SetProcessDpiAwareness(1) to enable system DPI awareness
  2. Queries the monitor's DPI using GetDpiForMonitor
  3. Provides scaling utilities for your application

On non-Windows platforms, the library is a simple passthrough to tkinter.Tk.

The implementation is based on this Stack Overflow answer.

Compatibility

Platform Status
Windows 10/11 Full DPI awareness support
Linux Passthrough (OS handles DPI)
macOS Passthrough (OS handles DPI)
Python Version Status
3.9+ Supported
3.8 Not supported (EOL)

Migrating from hdpitkinter

This package was formerly known as hdpitkinter. To migrate:

pip uninstall hdpitkinter
pip install tkinter-unblur
# Old
from hdpitkinter import HdpiTk
root = HdpiTk()

# New
from tkinter_unblur import Tk
root = Tk()

The HdpiTk name is still available as an alias for backwards compatibility:

from tkinter_unblur import HdpiTk  # Works, but Tk is preferred

License

MIT License - see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tkinter_unblur-2.0.0.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tkinter_unblur-2.0.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file tkinter_unblur-2.0.0.tar.gz.

File metadata

  • Download URL: tkinter_unblur-2.0.0.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tkinter_unblur-2.0.0.tar.gz
Algorithm Hash digest
SHA256 7c07821f3e5b21f4fe19252861939ea1c10694e8c8ed42a2cb6d6108fb4adaea
MD5 6d48c95ae7a3e27f6f0d293d0942406a
BLAKE2b-256 3c2f1ba55c77b5ed636d317dc13d4e16b452008d0d15af85785df505da8c5da7

See more details on using hashes here.

Provenance

The following attestation bundles were made for tkinter_unblur-2.0.0.tar.gz:

Publisher: publish.yml on unlibra/tkinter-unblur

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tkinter_unblur-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: tkinter_unblur-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tkinter_unblur-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 806aa2bfa65d43d427b5847d0d81b0b3bc845e8b991769c35471c1f10748e419
MD5 e908d79e617dbfec57b06128824584c1
BLAKE2b-256 11be5e96d93f8695b7ffedae5744bef5f9d55edf6401a71ab7fce1424ab204a1

See more details on using hashes here.

Provenance

The following attestation bundles were made for tkinter_unblur-2.0.0-py3-none-any.whl:

Publisher: publish.yml on unlibra/tkinter-unblur

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page