Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you obtain physical size of device in kivy?

Tags:

python

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.

like image 273
Psionman Avatar asked Jun 16 '16 11:06

Psionman


People also ask

How do I find the screen size of my KIVY?

Either through the config http://kivy.org/docs/api-kivy.config.html or through the cmd line args (try `python kivyapp.py --help` to see the available options). For android and ios the app should be fullscreen anyways so getting the window. size should give you the screen resolution.

What is DP in KIVY?

Using the dp unit is a simple solution to making the view dimensions in your layout resize properly for different screen densities. In others words, it provides consistency for the real-world size of your UI across different devices.


1 Answers

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()
like image 95
MajdSuhail Avatar answered Oct 04 '22 07:10

MajdSuhail