FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[Bug]: tkinter backend changes DPI awareness context of entire process on Windows · Issue #21875 · matplotlib/matplotlib · GitHub

Repository navigation

[Bug]: tkinter backend changes DPI awareness context of entire process on Windows #21875

Description

Bug summary

_BackendTk.new_figure_manager_given_figure calls _c_internal_utils.Win32_SetProcessDpiAwareness_max, which affects the entire process attached to the script, and all windows part of it, rather than just the matplotlib output window.

Ideally, the DPI awareness context should only be changed for the current thread before a matplotlib window is drawn and returned to the previous value afterwards, or at the very least there should be an option to disable the DPI change.

Code for reproduction

# reproduces the bug when run on a high DPI display on Windows

import tkinter as tk
from tkinter import ttk

import matplotlib
matplotlib.use('TkAgg')  # in case other GUI libraries are installed
import matplotlib.pyplot as plt

root = tk.Tk()

button = ttk.Button(root, text="Run matplotlib.pyplot.subplots",
                    command=plt.subplots)
button.pack(padx=30, pady=30)

root.wait_window()  #root.mainloop seems to prevent DPI updates

Actual outcome

The scaling of the window changes.

Expected outcome

The scaling of the window shouldn't change just because subplots was called.

Additional information

Introduced in #19167

Operating system

Windows 10

Matplotlib Version

3.5.0

Matplotlib Backend

TkAgg

Python version

3.9.6

Jupyter version

No response

Installation

pip

Activity

  1. richardsheridan commented on Dec 6, 2021

    Contributor

    As a workaround you can call ctypes.windll.shcore.SetProcessDpiAwareness(0) before engaging the TkAgg backend. It might be good to have a setting that causes TkAgg to skip setting DPI awareness since the semantics of it are weird.

  2. added this to the v3.5.1 milestone on Dec 6, 2021
  3. daniilS commented on Dec 6, 2021

    ContributorAuthor

    A potential way of avoiding this issue in Windows 10 version 1803 onwards would be to use SetThreadDpiHostingBehavior and SetThreadDpiAwarenessContext to only apply the scaling to a matplotlib popup window. Having a setting to disable it would always be good though when using an API call that applies to the entire process.

  4. modified the milestones: v3.5.1, v3.5.2 on Dec 10, 2021
  5. added a commit that references this issue on Dec 18, 2021
  6. modified the milestones: v3.5.2, v3.5.3 on Apr 30, 2022
  7. modified the milestones: v3.5.3, v3.5.4 on Jul 21, 2022
  8. modified the milestones: v3.5.4, v3.6.1 on Sep 25, 2022
  9. modified the milestones: v3.6.1, v3.6.2 on Oct 6, 2022
  10. modified the milestones: v3.6.2, v3.6.3 on Oct 27, 2022
  11. modified the milestones: v3.6.3, v3.7.0 on Jan 11, 2023
  12. modified the milestones: v3.7.0, v3.7.1 on Feb 14, 2023
  13. modified the milestones: v3.7.1, v3.7.2 on Mar 4, 2023
  14. modified the milestones: v3.7.2, v3.7.3 on Jul 5, 2023
  15. modified the milestones: v3.7.3, v3.8.0 on Sep 9, 2023
  16. removed this from the v3.8.0 milestone on Sep 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL