How to unite some subwidgets in kv like blocks

17 views
Skip to first unread message

Николай Чернобровин

unread,
May 15, 2018, 7:34:57 AM5/15/18
to Kivy users support
Good afternoon. I'm a novice developer on python3 kivy and I'm faced with this task. I need to unify the headers (several widgets - it's unchanged in all super widgets) and other extras. How can I (if) I can implement a general Python script (where is Builder.load_string ('' '...' '')?

    #!/usr/bin/kivy
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
from kivy.properties import ObjectProperty


class MainScreen(Screen):
    pass

class AnotherScreen(Screen):
    pass

class Main(Screen):
    pass

class ScreenManagement(ScreenManager):
    pass

present = Builder.load_string('''

#: kivy 1.9
#: import ScreenManager kivy.uix.screenmanager.ScreenManager
#: import Screen kivy.uix.screenmanager.ScreenManager
#: import FadeTransition kivy.uix.screenmanager.FadeTransition
#:import SwapTransition kivy.uix.screenmanager.SwapTransition

#:set color_button (227/255., 42/255., 76/255.,.8)

ScreenManager:
    id: screen_manager
    transition: SwapTransition()
    MainScreen:
        id: menu_screen
        name: 'MainScreen'
        manager: 'screen_manager'
    AnotherScreen:
        id: newgame_screen
        name: 'AnotherScreen'
        manager: 'screen_manager'
    Main: 
        id: loadgame_screen
        name: 'Main'
        manager: 'screen_manager'

<MainScreen>:
    BoxLayout:
        orientation: 'vertical'
        
        Button:
            text: 'AnotherScreen'
            font_size: 30
            on_release: app.root.current = 'AnotherScreen'
        Button:
            text: 'Load Game'
            font_size: 30
            on_release: app.root.current = 'Main'
       
<AnotherScreen>:
    FloatLayout: 
        canvas:
            Color:
                rgb: 1, 1, 1
            Rectangle:
                source: 'background2.png'
                size: 480, 720
        
        BoxLayout:       
            orientation: 'vertical' 
            spacing: 10

            BoxLayout:                  
                size_hint: 1,.15 
                #pos_hint: {'center_x': .5, 'center_y': .5}           

                canvas:
                    Color:
                        rgba: color_button
                    Rectangle:                        
                        size: self.size                         
                        pos: self.pos 

                Button:
                    background_normal: 'backicon.png' 
                    #size: self.size
                    size_hint: .5, .8 
                    background_color: 
                    pos_hint: {'center_x': .15, 'center_y': .5}
                    on_release: root.dismiss()

                Label:
                    background_normal: '' 
                    size_hint: 5,.25                    
                    text: '' 
                    font_size: 50 
                    pos_hint: {'center_x': .5, 'center_y': .5}                  
                    #bold: True

                Button:
                    id: btn
                    background_normal: 'menu2.png' 
                    size_hint: 1,1 
                    background_color: color_button
                    background_down: ''
                    pos_hint: {'center_x': .85, 'center_y': .5}
                    on_release: dropdown.open(self)      

                    DropDown:

                        id: dropdown
                        #on_parent: self.dismiss()
                        on_select: btn.text = '{}'.format(args[1])

                        Button:
                            text: 'Main'
                            background_color: color_button
                            background_normal: ''
                            size_hint_y: None
                            height: '48dp'
                            on_release: app.root.current = 'Main'

    BoxLayout:                  
                size_hint: 1,.85

<Main>:
    FloatLayout:
        BoxLayout:                  
            size_hint: 1,.85 

            Button:
                text: 'Third Item'
                size_hint_y: None
                height: '48dp'
                #on_release: dropdown.select('something')

            Button:
                text: 'Wow'
                size_hint_y: None
                height: '48dp'
                #on_release: dropdown.select('something')

Walmir Paiva

unread,
May 16, 2018, 10:19:02 AM5/16/18
to Kivy users support
Reply all
Reply to author
Forward
0 new messages