首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Kivy Image Widget未正确移动

Kivy Image Widget未正确移动
EN

Stack Overflow用户
提问于 2018-06-03 05:41:39
回答 1查看 284关注 0票数 0

如果您查看第一个GridLayout,就会发现其中有一个图像小部件。我正试着把它移到屏幕的右边。任何帮助都是适当的。这是代码。在右边我需要的小部件的id是id=image。我好像根本搬不动它。

我给出了更多细节,因为stackoverflow想要它。我认为上面的是非常详细的堆栈溢出,但你负责,所以这里有更多的文本。

谢谢大家。

代码语言:javascript
复制
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()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-03 06:16:35

在kv文件中,执行以下操作。具体请参考下面的示例。

  1. GridLayout:替换为BoxLayout:由于采用GridLayoutcols: 1与采用pos_hint: {'right': 1}

BoxLayout具有相似的演示文稿,因此请添加采用BoxLayout:pos_hint: {'right': 0.5}

备注

GridLayout没有名为orientation的属性。

示例

main.py

代码语言:javascript
复制
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()

输出

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50661401

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档