Skip to content

Why use the screen module?

Kivy's screen module is handy for emulating different screen sizes and dpis. This means that by using your dev machine, you can check out what your Kivy application would look like on other devices without having them. This is preferable to just guessing what your app would look like, but is in no way a replacement for actually having a test device.

Using Kivy's screen module to emulate devices

In this blog post, I will assume that you already followed the Tkinter VS Kivy Tutorial Quickstart and the How to install Kivy installation guide for your OS to install Kivy and an example project.

There is no special install or setup to use the screen module. It is built-in when you have installed Kivy.

To check it out, change directory with cd to the correct folder.

Make sure your virtual environment is setup with poetry shell!

Run this command:

$ python main.py -m screen:s3

How to the module command works:

First you call python and the script name: main.py

The -m means that you are running a Python module.

screen:s3 means that you are running the screen module with argument s3.

Examples on Windows, try them out!

Emulating an s3 screen.

Command:

$ python main.py -m screen:s3

Emulating an iphone6 screen.

Command:

$ python main.py -m screen:phone_iphone_6

How to add a custom device

To add your own device, go to the screen.py module in Kivy. If you have followed our install tutorial, you can simply to go your .venv folder, find kivy, and then go here:

.venv/lib/site-packages/kivy/modules/screen.py

I did not follow any tutorial! How do I find my environment?

If you did not follow any tutorial, you can find your environment with Python only.

Reference: Finding your Python env

Steps:

Type python in your terminal.

Type import sys. Press Enter

Type print(sys.prefix). Press Enter.

That folder will be where your Kivy install is, and subsequently your screen module as well.

Next, to add a custom device, follow the format of the devices dictionary, and add your device as follows:

$ 'fake_device_name': ('my_device_name', width, height, dpi, density),

Next, call your custom device!

Command:

$ python main.py -m screen:fake_device

Examples on MacOS, try them out!

Emulating an s3 screen.

Command:

$ python main.py -m screen:s3

Emulating an iphone6 screen.

Command:

$ python main.py -m screen:phone_iphone_6

How to add a custom device

To add your own device, go to the screen.py module in Kivy. If you have followed our install tutorial, you can simply to go your .venv folder, find kivy, and then go here:

.venv/lib/site-packages/kivy/modules/screen.py

I did not follow any tutorial! How do I find my environment?

If you did not follow any tutorial, you can find your environment with Python only.

Reference: Finding your Python env

Steps:

Type python in your terminal.

Type import sys. Press Enter

Type print(sys.prefix). Press Enter.

That folder will be where your Kivy install is, and subsequently your screen module as well.

Next, to add a custom device, follow the format of the devices dictionary, and add your device as follows:

$ 'fake_device_name': ('my_device_name', width, height, dpi, density),

Next, call your custom device!

Command:

$ python main.py -m screen:fake_device

On the Mac M1, you may need to use the scale command to get the screen to be the correct size:

Other relevant commands: portrait and scale

Other commands to try out:

Portrait mode:

$ python main.py -m screen:phone_samsung_galaxy_s5,portrait

Portrait and scale:

$ python main.py -m screen:tablet_nexus_7_13,portrait,scale=.75

Where to find screen data?

https://www.sven.de/dpi/

  • has a list of common dpis and phone resolutions

Article Error Reporting

Message @BadMetrics on the Kivy Discord.