如何在Kivy的TabbedPanel中设置图像大小?

问题描述 投票:0回答:1

我正在尝试设置图像的大小,这是TabbedPanel的子项。

enter image description here

如何增加添加图像的大小(如上所示,它很小)并使其响应任何屏幕调整大小事件。以下是我的代码段。

TabbedPanel:
    do_default_tab: False
    tab_height:20
    tab_width: self.parent.width / 4
    TabbedPanelItem:
        text: "ONE"
        Image:
            src: "img.jpg"
            size: 400, 500
            allow_stretch: True
            keep_ratio: True
    TabbedPanelItem:
        text: "TWO"
        Image:
            src: " "
            size: 400, 500
            allow_stretch: True
            keep_ratio: True

图像小部件是否应该包含在另一个布局中?谢谢你的时间。

image layout kivy
1个回答
0
投票

Solution

有关详细信息,请参阅示例。

  1. src:替换source:
  2. 删除size: 400, 500

Example

卖弄.朋友

from kivy.app import App
from kivy.uix.tabbedpanel import TabbedPanel
from kivy.lang import Builder

Builder.load_string("""

<Test>:
    do_default_tab: False
    tab_height:20
    tab_width: self.width / 4

    TabbedPanelItem:
        text: "ONE"
        Image:
            source: "brown-bear-150x150.jpg"
            allow_stretch: True
            keep_ratio: True

    TabbedPanelItem:
        text: "TWO"
        Image:
            source: "grizzly-bear-150x150.jpg"
            allow_stretch: True
            keep_ratio: True

    TabbedPanelItem:
        text: 'THREE'
        Image:
            source: "giant-panda-150x150.jpg"
            allow_stretch: True
            keep_ratio: True

    TabbedPanelItem:
        text: 'FOUR'
        Image:
            source: "polar-bear-150x150.jpg"
            allow_stretch: True
            keep_ratio: True


""")


class Test(TabbedPanel):
    pass


class TabbedPanelApp(App):
    def build(self):
        return Test()


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

Output

Img01 Img02 Img03

© www.soinside.com 2019 - 2024. All rights reserved.