1

I have two screens in a Kivy program. The first one represents the login screen, so it needs to be smaller, while the other has the data, so I need to make it full screen.

I tried to use

from kivy.config import Config
Config.set('graphics', 'width', '350')
Config.set('graphics', 'height', '250')

But, the problem is with this the other screen's size has also decreased, help me if you have any idea what I need to do to have different sizes for different screens, thanks.

Mahdi
  • 133
  • 13
  • Possible duplicate of [How to change window size?](http://stackoverflow.com/questions/14014955/how-to-change-window-size) – Amin Etesamian Mar 03 '17 at 01:32
  • No its not, here I am trying to change sizes for two different windows not for a single windows (which the mentioned question answers) – Mahdi Mar 03 '17 at 02:46

2 Answers2

1

I answered almost the identical question earlier today. Code your python similar to this:

from kivy.app import App
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.core.window import Window

class Screen_Manager(ScreenManager):
    pass

class Main(Screen):
    def __init__(self, **kwargs):
        super(Main, self).__init__(**kwargs)

    def on_pre_enter(self):
        Window.size = (900, 500)     

class Login(Screen):
    def __init__(self, **kwargs):
        super(Login, self).__init__(**kwargs)

    def on_pre_enter(self):
        Window.size = (400, 300)


class MultiScreenApp(App):
    def build(self):
        return Screen_Manager()

MultiScreenApp().run()

with a multiscreen.kv file similar to this:

<Screen_Manager>:
    id: screen_manager
    Login:
    Main:

<Login>:
    name: 'login'
    Button:
        text: 'Go to Main'
        on_press: root.manager.current = 'main'

<Main>:
    name: 'main'
    Button:
        text: 'Go to Login'
        on_press: root.manager.current = 'login'
RufusVS
  • 4,008
  • 3
  • 29
  • 40
0

Define a method like

from kivy.core.window import Window

def update_window_size(width, height):
    # Validate width and height then
    Window.size = (width, height)

and call it with the desired height and width anywhere you want.

___ Edit 1 - Adding sample. Change Screen size in the Screen's initilization

from kivy.app import App
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.core.window import Window

sm = ScreenManager()


class Main(Screen):
    def __init__(self):
        super(Main, self).__init__()


class Login(Screen):
    def __init__(self):
        super(Login, self).__init__()
        # Change login screen size in it's __init__
        update_window_size(250, 250)


def update_window_size(width, height):
    # Validate width and height then
    Window.size = (width, height)


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

MyApp().run()
Amin Etesamian
  • 3,363
  • 5
  • 27
  • 50
  • Thanks a lot but I am quite new to Kivy, can you please expalin this with an example, like for example O have two classes for two screens: class LoginScreen(Screen) for : and class DataDisplayScreen(class) for how should I move forward?? Thanks – Mahdi Mar 03 '17 at 19:24
  • @Mahdi I added a sample with two screens – Amin Etesamian Mar 03 '17 at 19:31
  • Thanks again fr the effort, but I getting this error: child = cls(__no_builder=True) TypeError: __init__() got an unexpected keyword argument '__no_builder' – Mahdi Mar 03 '17 at 19:44