【问题标题】:How to set image size inside TabbedPanel in Kivy?如何在 Kivy 的 TabbedPanel 中设置图像大小?
【发布时间】:2019-01-05 19:59:13
【问题描述】:

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

如何增加添加的图像的大小(如上图所示)并使其响应任何屏幕调整大小事件。下面是我的代码sn-p。

.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

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

【问题讨论】:

  • src: 替换为source:。您已经为 Image 定义的内容可以正常工作。
  • 感谢您的回复。更改为来源,仍然有相同的大小调整问题..
  • 请以示例查看我的帖子。

标签: image layout kivy


【解决方案1】:

解决方案

详情请参考示例。

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

输出

【讨论】:

    猜你喜欢
    • 2017-01-24
    • 1970-01-01
    • 1970-01-01
    • 2020-08-29
    • 2018-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多