4

As premise: I'm a beginner in the world of programming.

I would like to create my first application which should run on different devices, i.e. Smartphones or tablets with different screen sizes.

The main window should adapt automatically to the height of the device. I found on this forum two ways to control window size.

With the first one, I can determine the window size:

from kivy.config import Config
Config.set('graphics', 'width',  200)
Config.set('graphics', 'height', 100)

But this is a static method with constant values. Alternatively, I could set the window to full screen:

from kivy.config import Config
Config.set('graphics', 'fullscreen', 1)

This way the window covers the whole display and changes the proportion of the window and of the widgets inside…

Is there a way to get the display height and use it to build my window?

TylerH
  • 20,799
  • 66
  • 75
  • 101
dade100
  • 165
  • 1
  • 10
  • 1
    Set the size of widgets relative to the `Window.height` and `Window.width` so UI looks the same in different screen resolutions. – Amin Etesamian Feb 27 '17 at 16:26
  • Is it possible to set Window.height to the maximum available height (the height of the screen)? – dade100 Feb 27 '17 at 17:41
  • You want a fullscreen app that takes the whole display? – Amin Etesamian Feb 27 '17 at 18:23
  • I would like to set the window height to the maximum height and than calculate the width basing on it (for example: width = height *2 / 3). I mean: can I get somehow the dimension (inch, pixel,...) of the screen where the app has to be displayed on? – dade100 Feb 27 '17 at 21:34

1 Answers1

0

One way is to check the platform and try getting the dimension based on the platform. for example on linux you could run xdpyinfo | grep dimensions to get the screen resolution or on windows from win32api import GetSystemMetrics is used for getting the resolution or on android you could us pyjnius to Get screen dimensions in pixels

as an example, for linux you could

import subprocess

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.label import Label
from kivy.utils import platform

class Main(Widget):
    def __init__(self):
        super(Main, self).__init__()
        if platform == 'linux':
            command = "xdpyinfo  | grep -oP 'dimensions:\s+\K\S+'"
            ps = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
            output = ps.communicate()[0]
            self.add_widget(Label(text=output))


class MyApp(App):
    def build(self):
        return Main()

MyApp().run()
Community
  • 1
  • 1
Amin Etesamian
  • 3,363
  • 5
  • 27
  • 50