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 (in some cases). 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 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 do what you want, hence we have explained both.


Method 1#: Scaling

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

import tkinter as tk

root = tk.Tk()
root.geometry("200x150")
root.tk.call('tk', 'scaling', 2.0)

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

root.mainloop()

What this does is similar to zooming in and out. A scale of 2.0 will 2x the size of all widgets and text, whereas a scale of 0.5 will do the opposite. This method might come in handy if you want to implement zooming in and out of widgets on your tkinter screen.

Remember to call this function, before placing any widgets, otherwise it will not effect the widgets created before it’s call.

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


Method 2#: Ctypes

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()

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. 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!

Subscribe
Notify of
guest
6 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments