Getting the device's screen resolution

66 views
Skip to first unread message

Auggie

unread,
May 13, 2018, 9:11:33 PM5/13/18
to Kivy users support
Is there a way to get the device's screen resolution with Kivy, so I can assign it to a variable? I have been using PyAutoGUI for that purpose, but would much rather do it with Kivy, if possible. 

Pieter van der Meer

unread,
May 14, 2018, 1:37:43 AM5/14/18
to kivy-...@googlegroups.com
https://kivy.org/docs/api-kivy.core.window.html#kivy.core.window.WindowBase.size

from kivy.core.window import Window
size = Window.size print("display size =", size)

On Mon, May 14, 2018 at 3:11 AM, Auggie <theviol...@gmail.com> wrote:
Is there a way to get the device's screen resolution with Kivy, so I can assign it to a variable? I have been using PyAutoGUI for that purpose, but would much rather do it with Kivy, if possible. 

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Pieter van der Meer
System engineer / Owner
Tasty Chips Electronics
www.tastychips.nl

Auggie

unread,
May 14, 2018, 2:15:39 PM5/14/18
to Kivy users support
Thank you for your answer! When I run your code, I get: display size = (800, 600). This seems to be the default window size in kivy. My screen resolution is 3000x2000 (Surface book 2, 13.5 inch), so I'm looking for a similar code that will give me: display size = (3000, 2000), or whatever the screen resolution is on any given device, including phones and tablets. Thanks! 

On Sunday, May 13, 2018 at 10:37:43 PM UTC-7, Pieter van der Meer wrote:
https://kivy.org/docs/api-kivy.core.window.html#kivy.core.window.WindowBase.size

from kivy.core.window import Window
size = Window.size print("display size =", size)
On Mon, May 14, 2018 at 3:11 AM, Auggie <theviol...@gmail.com> wrote:
Is there a way to get the device's screen resolution with Kivy, so I can assign it to a variable? I have been using PyAutoGUI for that purpose, but would much rather do it with Kivy, if possible. 

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Quadri Ganiu

unread,
May 14, 2018, 3:34:29 PM5/14/18
to kivy-...@googlegroups.com
Try this
class MyApp(App):
    def on_start(self):
        print( self.root_window.size )

Or

instance.bind(size=myfunc)

def myfunc(inst, value):
    print( Window().size )

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+unsubscribe@googlegroups.com.

Auggie

unread,
May 14, 2018, 4:44:39 PM5/14/18
to Kivy users support
Thank you for your answer! The first suggestion still returns (800, 600). I couldn't figure out how to make the second suggestion work. 

ZenCODE

unread,
May 16, 2018, 7:59:19 AM5/16/18
to Kivy users support
# -*- coding: utf-8 -*-
from kivy.app import App
from kivy.uix.label import Label
from kivy.core.window import Window


class TestApp(App):
def build(self):
label = Label(text="Initial Size = {0}".format(Window.size))

def on_size(win, size):
label.text = "on_size. Size={0}".format(size)

Window.bind(size=on_size)
return label

TestApp().run()
Reply all
Reply to author
Forward
0 new messages