Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kivy app is blurry on windows with high resolution screen

I am having trouble with my kivy app. The text is blurry on my high resolution windows laptop (3840x2160). It works fine on a Mac with retina display and on a windows PC lower resolution. As seen in the following screenshot.

screenshot of app

This is my test code:

import kivy
from kivy.app import App
from kivy.uix.label import Label
from kivy.config import Config
Config.set('graphics', 'width', '200')
Config.set('graphics', 'height', '100')

class MyApp(App):
    def build(self):
        return Label(text="why is this blurry")

if __name__ == "__main__":
    MyApp().run()

And this the console output:

[INFO   ] [Logger      ] Record log in C:\Users\lucas\.kivy\logs\kivy_22-04-01_6.txt
[INFO   ] [deps        ] Successfully imported "kivy_deps.angle" 0.3.2
[INFO   ] [deps        ] Successfully imported "kivy_deps.glew" 0.3.1
[INFO   ] [deps        ] Successfully imported "kivy_deps.sdl2" 0.4.5
[INFO   ] [Kivy        ] v2.1.0
[INFO   ] [Kivy        ] Installed at "C:\Users\lucas\kivytest\env\lib\site-packages\kivy\__init__.py"
[INFO   ] [Python      ] v3.9.10 (tags/v3.9.10:f2f3f53, Jan 17 2022, 15:14:21) [MSC v.1929 64 bit (AMD64)][INFO   ] [Python      ] Interpreter at "C:\Users\lucas\kivytest\env\Scripts\python.exe"       
[INFO   ] [Logger      ] Purge log fired. Processing...
[INFO   ] [Logger      ] Purge finished!
[INFO   ] [Factory     ] 189 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2 (img_pil, img_ffpyplayer ignored)
[INFO   ] [Text        ] Provider: sdl2
[INFO   ] [Window      ] Provider: sdl2
[INFO   ] [GL          ] Using the "OpenGL" graphics system
[INFO   ] [GL          ] GLEW initialization succeeded
[INFO   ] [GL          ] Backend used <glew>
[INFO   ] [GL          ] OpenGL version <b'4.6.14757 Compatibility Profile Context FireGL 20.45.01.45 27.20.14501.45003'>
[INFO   ] [GL          ] OpenGL vendor <b'ATI Technologies Inc.'>
[INFO   ] [GL          ] OpenGL renderer <b'AMD Radeon(TM) Pro Graphics'>
[INFO   ] [GL          ] OpenGL parsed version: 4, 6
[INFO   ] [GL          ] Shading version <b'4.60'>
[INFO   ] [GL          ] Texture max size <16384>
[INFO   ] [GL          ] Texture max units <32>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO   ] [Base        ] Start application main loop
[INFO   ] [GL          ] NPOT texture support is available

This issues seems to be related to this: https://github.com/kivy/kivy/issues/3705

or this: https://github.com/kivy/kivy/pull/7299

or this: https://github.com/kivy/kivy/pull/7293

But none of the suggestions seem to work for me. Any idea how to reslove this?

like image 871
Lucas Avatar asked Nov 29 '25 13:11

Lucas


2 Answers

The solution is basically in the second link that I posted : https://github.com/kivy/kivy/pull/7299

I also posted a question in that thread when I didn't get any responses here, but will copy my solution here.

When I did the following:

from ctypes import windll
windll.user32.SetProcessDpiAwarenessContext(-4)
lastError = windll.kernel32.GetLastError()
print(lastError)

I got the error 87 which corresponds to ERROR_INVALID_PARAMETER. So something had to be wrong with the -4. I dug around the windll and found the following fix:

from ctypes import windll, c_int64
windll.user32.SetProcessDpiAwarenessContext(c_int64(-4))
like image 158
Lucas Avatar answered Dec 01 '25 02:12

Lucas


The second link you posted provided this information:

from ctypes import windll
windll.user32.SetProcessDpiAwarenessContext(-4)

Now this does not work, so we have to add c_int64, something found in the same module.

from ctypes import windll, c_int64
windll.user32.SetProcessDpiAwarenessContext(c_int64(-4))

Now it will work!

Edit: I did not realize earlier that you had already figured it out!

like image 24
Aarav Dave Avatar answered Dec 01 '25 02:12

Aarav Dave



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!