starting with Screen Manager

1,876 views
Skip to first unread message

حسن حيدري نسب

unread,
Sep 10, 2013, 12:31:15 PM9/10/13
to kivy-...@googlegroups.com
Hi everyone
I'm New here. I couldn't use from screen manager when it's with kv.
Can you help me to use Screen Manager without kv part?
? How i can use subclass in python (not kv language) to create a layout on a Screen

David Farris

unread,
Sep 10, 2013, 3:42:07 PM9/10/13
to kivy-...@googlegroups.com
you might want to take a look at kivy\examples\widgets\screenmanager.py 

essentially you just create a class with the screen object and add it to your app. then you can add widgets to your screen object


class MainScreen(Screen):
   
self.add_widget(Button())

class NameApp(App):
   
def build(self):
        root
= ScreenManager()
        root
.add_widget(MainMenu(name='Main'))
       
return root

حسن حيدري نسب

unread,
Sep 11, 2013, 4:20:19 AM9/11/13
to kivy-...@googlegroups.com
It shows a big widget. I want to create a layout like GridLayout ....


در چهارشنبه 11 سپتامبر 2013، ساعت 0:12:07 (UTC+4:30)، David Farris نوشته:

Gabriel Pettier

unread,
Sep 11, 2013, 4:53:03 AM9/11/13
to kivy-...@googlegroups.com
ScreenManager doesn't do that, you probably want to put ScreenManager
inside your GridLayout if you want for example, a menu atop the
screenmanager which controls it. If you want the opposite, a GridLayout
inside a Screen, then just do it the same way, widgets/layouts are meant
to be nested.
> --
> 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/groups/opt_out.

David Farris

unread,
Sep 11, 2013, 7:35:02 AM9/11/13
to kivy-...@googlegroups.com
If you haven't already, take the time to go through the entire examples directory and try to understand how each example works, line by line. It helped me a lot.

حسن حيدري نسب

unread,
Sep 11, 2013, 8:33:10 AM9/11/13
to kivy-...@googlegroups.com
I did read it before but it wrote via kv part and i want to create a GridLayout out of kv language.
How do i use to Subclass for it (in python oniy) for control a Screen?

حسن حيدري نسب

unread,
Sep 11, 2013, 8:38:20 AM9/11/13
to kivy-...@googlegroups.com
Can you give me an example about Screen Manager that has two Screens and one GridLayout in each them without any kv language part ?
Thanks

David Farris

unread,
Sep 11, 2013, 11:33:17 AM9/11/13
to kivy-...@googlegroups.com
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.properties import NumericProperty
from kivy.lang import Builder

Builder.load_string('''
#:import random random.random
#:import SlideTransition kivy.uix.screenmanager.SlideTransition
#:import SwapTransition kivy.uix.screenmanager.SwapTransition
#:import WipeTransition kivy.uix.screenmanager.WipeTransition
#:import FadeTransition kivy.uix.screenmanager.FadeTransition
<CustomScreen>:
    hue: random()
    canvas:
        Color:
            hsv: self.hue, .5, .3
        Rectangle:
            size: self.size

    Label:
        font_size: 42
        text: root.name
    GridLayout:
        cols: 3
        size_hint: .5, None
        height: 250
        pos_hint: {'center_x': .5}

       
        Button:
            text: 'Next screen'
            on_release: root.manager.current = root.manager.next()
   
        Button:
            text: 'Previous screen'
            on_release: root.manager.current = root.manager.previous()


        Button:
            text: 'Slide "up"'
            on_release: root.manager.transition = SlideTransition(direction="up")

        Button:
            text: 'Slide "down"'
            on_release: root.manager.transition = SlideTransition(direction="down")

        Button:
            text: 'Slide "left"'
            on_release: root.manager.transition = SlideTransition(direction="left")

        Button:
            text: 'Slide "right"'
            on_release: root.manager.transition = SlideTransition(direction="right")

        Button:
            text: 'Swap'
            on_release: root.manager.transition = SwapTransition()

        Button:
            text: 'Wipe'
            on_release: root.manager.transition = WipeTransition()

        Button:
            text: 'Fade'
            on_release: root.manager.transition = FadeTransition()
''')

class CustomScreen(Screen):
    hue = NumericProperty(0)

class ScreenManagerApp(App):


    def build(self):
        root = ScreenManager()
        for x in xrange(4):
            root.add_widget(CustomScreen(name='Screen %d' % x))
        return root

if __name__ == '__main__':
    ScreenManagerApp().run()

حسن حيدري نسب

unread,
Sep 11, 2013, 11:17:14 PM9/11/13
to kivy-...@googlegroups.com
I saw it before but it has the kv language part.
I want to put a GridLayout in each Screen and i want to do it without a kv language.
? there isn't any way

How can i use " self.add_widget(Button()) " on a screen ? (not "Button:" that is in kv part) .

Gabriel Pettier

unread,
Sep 12, 2013, 5:03:16 PM9/12/13
to kivy-...@googlegroups.com
Well, Screen is a Widget, so you can create your screen

screen = Screen(name='test')

add widgets to it

btn = Button(text='test')
button.bind(on_press=something)
screen.add_widget(button)

well, just like with any widget in kivy…

حسن حيدري نسب

unread,
Sep 13, 2013, 5:15:08 AM9/13/13
to kivy-...@googlegroups.com
Ow thank you very much
That worked!

Ken Samson

unread,
Sep 13, 2013, 8:26:23 AM9/13/13
to kivy-...@googlegroups.com
Can you share what worked? Basically building a screen by explicitly adding elements, like a grid layout in java/swing? Thank you.

Kenneth Boyd

unread,
Oct 14, 2015, 8:17:36 AM10/14/15
to Kivy users support
I know this is an old post, but I was looking for info on this and found a good example here: 

http://stackoverflow.com/questions/19491286/kivy-changing-screens-in-screen-manager-with-an-on-press-event


SERWANO JONATHAN

unread,
Nov 14, 2016, 9:05:37 AM11/14/16
to Kivy users support, tdf...@gmail.com
OOOOH men this is what have been looking for all week
thaks baddy
Reply all
Reply to author
Forward
0 new messages