Figures are wrong size after using tk.filedialog.askopenfilename()

I would like to use tk.filedialog.askopenfilename() to prompt for a file name. However, after doing this the Sciplot figures are the wrong size. I have not found a solution, but did try some suggestions like using root.destroy(). They did not help. This is a test case that demonstrates the problem. (It doesn’t use the result of askopenfilename(), but just has a simple plot.)

The plot is the wrong size (very small). If the lines involving tk are not used (False instead of True in the test case), it works as expected.

import tkinter as tk
from tkinter import filedialog
import matplotlib.pyplot as plt

if True:
	root = tk.Tk()
	root.withdraw()
	file_path = filedialog.askopenfilename()
	root.destroy()

plt.figure(figsize=(10,6))
y = range(1,10)
plt.plot(y)
plt.show()

This is on Windows 10 with Matplotlib 3.5.1 and Python 3.10. It is with a high resolution monitor (250%).

After writing this I did find a useful solution (among a lot of not useful ones):

import ctypes
ctypes.windll.shcore.SetProcessDpiAwareness(1)

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

Sorry about this, we added support for high-dpi in tk on windows is mpl3.5, but in keeping with all of the high-dpi related work, it has had some unintended consequences which will take a few versions to work through.