我正在尝试设置作为TabbedPanel子项的图像的大小。
如何增加所添加图像的尺寸(如上所示,该尺寸很小)并使之响应任何屏幕尺寸调整事件。以下是我的代码段。
.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
图像小部件是否应包含在其他布局中?感谢您的宝贵时间。
答案 0 :(得分:0)
有关详细信息,请参阅示例。
src:
替换为source:
。size: 400, 500
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()