How can I position my kivy app window in the right bottom corner

Question:

I have a kivy desktop app and want to start it in the corner at the right.
Currently, i can only apply the position from the left, top…

from kivy.config import Config
Config.set('graphics','position','custom')
Config.set('graphics','resizable',0)
Config.set('graphics','left',20)
Config.set('graphics','top',50)
Config.write()
Asked By: Medera

||

Answers:

I believe that using the left and top properties are the only way to position an app. If that is true, then you must get the size of the device screen, and use that to calculate the the top and left. However, getting the size of the device screen is difficult in python/kivy. You can get an approximation by maximizing the kivy window and using its size. Here is some code that follows this approach:

def do_maximize(self, dt):
    self.app_size = Window.size
    Window.maximize()
    Clock.schedule_once(self.adjust_window)

def adjust_window(self, dt):
    window_size = Window.size
    top = Window.top
    left = Window.left
    Window.restore()
    Window.top = window_size[1] - self.app_size[1] + top
    Window.left = window_size[0] - self.app_size[0] + left

And calling:

    Clock.schedule_once(self.do_maximize)

from the App.build() method should approximate what you want.

A more accurate, but more complex approach would be to use subprocess to run a command to capture the device size (something like xdpyinfo on Linux) and parse the output to get the size.

Answered By: John Anderson

thank you @John Anderson your solution worked, i had only to apply one line for my needs.

def do_maximize(self, dt):
    self.app_size = Window.size
    Window.maximize()
    Clock.schedule_once(self.adjust_window)

def adjust_window(self, dt):
    window_size = Window.size
    top = Window.top - 50
    left = Window.left
    Window.restore()
    Window.size = (400, 200) # new (desired window size)
    self.app_size = Window.size
    Window.top = window_size[1] - self.app_size[1] + top
    Window.left = window_size[0] - self.app_size[0] + left
Answered By: Medera
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.