Skip to content
Advertisement

Can you obtain physical size of device in kivy?

Does anyone know how Kivy renders text in different fonts?

I have labels with text at 16sp.

On a tablets with screen sizes (1024, 552) and (2048, 1536) it works perfectly (width/height ratios 1.855 and 1.333 respectively) enter image description here

On the pc with screen size (1280, 720) (ratio 1.778) it also displays perfectly, but on a phone with this screen size the letters are truncated enter image description here

The only difference here is the physical size of the device. It thus appears, that Kivy text is not rendered according to some algorithm based on pixels, but takes into account the physical size of the screen

Is there any way to determine the physical size in Kivy? and hence allow me to adjust font size accordingly. The text appears correctly on the phone (small device) if I use a smaller (10sp) font size, but then it appears too small on the larger devices.

Advertisement

Answer

Yes, you can determine the physical size of screen with kivy – You could simply use this Module:

(from kivy.core.window import Window)

and then determine sizes by writing this:

(Window.size)

Check this code out (this code determines screen physical sizes on a simple label):

⬇️⬇️

from kivy.app import App
from kivy.uix.label import Label
from kivy.core.window import Window

class MyApp(App):

   def build(self):

     window_sizes=Window.size

     return Label(text="screen sizes= "+str(window_sizes))

MyApp().run()
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement