How to improve Tkinter window resolution



Often, when working with Tkinter you’ll notice a certain amount of screen blur or low resolutions windows. This becomes more apparent when you have text appearing on your window as it appears noticeably blurry. You might wonder, is there a way to improve the resolution of this Tkinter window?

Luckily, there is a short and simple fix for this issue, that sadly not too many people actually know. There are two known ways which we can use. It’s possible that only one of these two ways will actually work for you, hence we have two.


The first way is using the call() function to change the resolution scaling.

import tkinter as tk

root = tk.Tk()
root.geometry("200x150")

label = tk.Label(root, text = "Hello World")
label.pack(padx = 5, pady = 5)

root.tk.call('tk', 'scaling', 2.0)
root.mainloop()

Keep in mind this will also effect the size of the tkinter window. Basically, you increasing the pixel density by increasing scaling, hence you will have to increase the number of pixels to maintain the same size as before.

2.0 was merely the value we used. You can change this value to see what suits you best.


The second method is the use of the ctypes Python library. This following setting in the ctypes library sets “DPI” awareness. DPI stands for Dots per inch, another way of measuring screen resolution.

import tkinter as tk
import ctypes

ctypes.windll.shcore.SetProcessDpiAwareness(1)

root = tk.Tk()
root.geometry("200x150")

label = tk.Label(root, text = "Hello World")
label.pack(padx = 5, pady = 5)

root.mainloop()

Just like the previous method, this will also effect the screen resolution. Adjust the value in the brackets to see what suits your screen the best.


Comparison

Here is a side by side comparison of both tkinter windows, with and without the GUI fix. It is fairly obvious which one is the high resolution one. Also notice the difference in sizes. Increasing pixel density while not changing the number of pixels will result in smaller window sizes.

CodersLegacy Tkinter window resolution comparison
Before – After Comparision

This marks the end of the improve Tkinter window resolution Article. Any suggestions or contributions to CodersLegacy are more than welcome. Any questions can be directed to the comments section below.

See more Tkinter related tit bits in the Problem solving section!

Leave a Reply

Your email address will not be published. Required fields are marked *