Is there a built-in function or straight-forward way to get the resolution of a maximized window in Python (e.g. on Windows full screen without the task bar)? I have tried several things from other posts, which present some major drawbacks:
- ctypes
import ctypes
user32 = ctypes.windll.user32
screensize = user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)
Simple, but I get the resolution of the full screen.
- tkinter
import tkinter as tk
root = tk.Tk() # Create an instance of the class.
root.state('zoomed') # Maximized the window.
root.update_idletasks() # Update the display.
screensize = [root.winfo_width(), root.winfo_height()]
root.mainloop()
Works, but it isn't really straight-forward and above all, I don't know how to exit the loop with root.destroy() or root.quit() successfully. Closing the window manually is of course not an option.
- matplotlib
import matplotlib.pyplot as plt
plt.figure(1)
plt.switch_backend('QT5Agg')
figManager = plt.get_current_fig_manager()
figManager.window.showMaximized()
print(plt.gcf().get_size_inches())
[6.4 4.8]
is then printed, but if I click on the created window, and execute print(plt.gcf().get_size_inches())
again, I get [19.2 10.69]
printed, which I find higly inconsistent! (As you can imagine, having to interact to get that final value is definitely not an option.)