Kivy application for different devices

As a premise: I am new to the programming world.

I would like to create my first application, which should run on different devices, that is, on smartphones or tablets with different screen sizes.

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

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

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)

Thus, the window covers the entire screen and changes the proportion of the window and widgets inside ...

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

+4
1

- . , linux xdpyinfo | grep dimensions, from win32api import GetSystemMetrics , pyjnius

, linux

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

Source: https://habr.com/ru/post/1670911/


All Articles