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

时间:2018-07-29 10:04:15

标签: image layout kivy

我正在尝试设置作为TabbedPanel子项的图像的大小。

enter image description here

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

.kv

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

图像小部件是否应包含在其他布局中?感谢您的宝贵时间。

1 个答案:

答案 0 :(得分:0)

解决方案

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

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

示例

main.py

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()

输出

Img01 Img02 Img03