Carl Von
Carl Von

Reputation: 178

Kivy Image Widget not Moving Right

If you look under the first GridLayout there is an Image widget. I'm trying to get it to move to the right side of the screen. Any help is appropriated. Here's the code. The id of the widget I need on the right hand side is id=image. I can't seem to move it at all.

I'm giving more details because stackoverflow want's it. I think the above is pretty detailed really stackoverflow, but your in charge so here is more text.

Thank you everyone.

from kivy.lang import Builder
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen, NoTransition


Builder.load_string("""
<ClientScreen>:
    GridLayout:
        id: main_grid_layout
        orientation: 'vertical'
        cols: 1
        Label:
            id: name_label
            text: '<NO MENU NAME>'
            size_hint_y: None
            size: self.texture_size 
            halign: 'left'
            valign: 'center'
            text_size: self.size
            padding_x: 35
            canvas.before:
                Color:
                    rgb: .6, .6, .6
                Rectangle:
                    pos: self.pos
                    size: self.size
        Image:
            id: image
            pos_hint: {'right': 0.5}
        ScrollView:
            id: text_scroll_view
            bar_width: 10
            size: self.size
            GridLayout:
                id: text_grid_layout
                orientation: 'vertical'
                cols: 1
                size_hint_y: None
                height: self.minimum_height
        ScrollView:
            size: self.size
            bar_width: 10
            size_hint_y: 0.40
            GridLayout:
                id: action_grid_layout
                # padding: [10, 10, 10, 10]
                orientation: 'vertical'
                cols: 1
                size_hint_y: None
                # row_default_height: 30
                height: self.minimum_height
""")


class LoginScreen(Screen):
    pass


class ClientScreen(Screen):
    pass


class MyApp(App):
    def build(self):
        from kivy.core.window import Window

        sm = ScreenManager()
        sm.transition = NoTransition()

        global CLIENT_SCREEN

        LOGIN_SCREEN = LoginScreen(name='login')
        CLIENT_SCREEN = ClientScreen(name='client')

        sm.add_widget(LOGIN_SCREEN)
        sm.add_widget(CLIENT_SCREEN)

        sm.current = 'client'

        Window.size = (300, 120)
        self.title = 'xNemesis Client V0'

        return sm


MyApp().run()

Upvotes: 0

Views: 512

Answers (1)

ikolim
ikolim

Reputation: 16031

In the kv file, do the following. Please refer to the example below for details.

  1. Replace GridLayout: with BoxLayout: because GridLayout with cols: 1 has the similar presentation as BoxLayout with orientation: 'vertical'.
  2. Remove cols: 1
  3. At Image:, add size_hint_x: 0.4
  4. Replace pos_hint: {'right': 0.5} with pos_hint: {'right': 1}

Note

GridLayout does not has an attribute called orientation.

Example

main.py

from kivy.lang import Builder
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen, NoTransition


Builder.load_string("""
<ClientScreen>:
    BoxLayout:
        id: main_grid_layout
        orientation: 'vertical'
        Label:
            id: name_label
            text: '<NO MENU NAME>'
            size_hint_y: None
            size: self.texture_size 
            halign: 'left'
            valign: 'center'
            text_size: self.size
            padding_x: 35
            canvas.before:
                Color:
                    rgb: .6, .6, .6
                Rectangle:
                    pos: self.pos
                    size: self.size
        Image:
            id: image
            source: 'raspberrypi.png'
            size_hint_x: 0.4
            pos_hint: {'right': 1}
        ScrollView:
            id: text_scroll_view
            bar_width: 10
            size: self.size
            GridLayout:
                id: text_grid_layout
                orientation: 'vertical'
                cols: 1
                size_hint_y: None
                height: self.minimum_height
        ScrollView:
            size: self.size
            bar_width: 10
            size_hint_y: 0.40
            GridLayout:
                id: action_grid_layout
                # padding: [10, 10, 10, 10]
                orientation: 'vertical'
                cols: 1
                size_hint_y: None
                # row_default_height: 30
                height: self.minimum_height
""")


class LoginScreen(Screen):
    pass


class ClientScreen(Screen):
    pass


class MyApp(App):
    def build(self):
        from kivy.core.window import Window

        sm = ScreenManager()
        sm.transition = NoTransition()

        global CLIENT_SCREEN

        LOGIN_SCREEN = LoginScreen(name='login')
        CLIENT_SCREEN = ClientScreen(name='client')

        sm.add_widget(LOGIN_SCREEN)
        sm.add_widget(CLIENT_SCREEN)

        sm.current = 'client'

        Window.size = (300, 120)
        self.title = 'xNemesis Client V0'

        return sm


MyApp().run()

Output

Img01 - App Startup

Upvotes: 1

Related Questions