我是Kivy的新手,我正在尝试使用kivy和scrollview。我需要停止按钮的背景图像从拉伸,我希望按钮看起来像第一个图像。我正在使用background_normal将背景图像添加到按钮。我需要在网格布局中更改row_default_height: root.height*0.3吗?或者我在每个按钮上添加一个图像的高度和宽度?如何停止调整图像的大小?
任何帮助都会很好,谢谢你:)

我的.kv文件
#: import FadeTransition kivy.uix.screenmanager.FadeTransition
#: import GridLayout kivy.uix.gridlayout
#: import BoxLayout kivy.uix.boxlayout
#: import ButtonBehavior kivy.uix.button
#: import Image kivy.uix.image
#: import Window kivy.core.window.Window
ScreenManager:
transition: FadeTransition()
MainScreen:
AnotherScreen:
<MainScreen>:
name: "main"
BoxLayout:
ScrollView:
GridLayout:
some_property: setattr(Window, 'fullscreen' , 'auto') or 'real_value!'
id: container_y
size_hint_y: None
cols: 2
row_default_height: root.height*0.3
height: self.minimum_height
Image:
source: "teaflav/Crushes.png"
Button:
background_normal: 'teaflav/Crushes.png'
on_release: app.root.current ="other"
height: 40
Button:
background_normal: 'teaflav/Crushes.png'
on_release: app.root.current ="other"
height: 40
Button:
background_normal: 'teaflav/Crushes.png'
on_release: app.root.current ="other"
height: 40
Button:
background_normal: 'teaflav/Crushes.png'
on_release: app.root.current ="other"
height: 40
Button:
background_normal: 'teaflav/Crushes.png'
on_release: app.root.current ="other"
height: 40发布于 2020-12-28 22:42:12
通过派生新类来创建ImageButton。
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.behaviors import ButtonBehavior
from kivy.uix.image import Image
kv = """
#: import FadeTransition kivy.uix.screenmanager.FadeTransition
ScreenManager:
transition: FadeTransition()
MainScreen:
name: "main"
AnotherScreen:
name: 'other'
<AnotherScreen@Screen>:
Button:
text: 'Return to Main'
on_release: root.manager.current = 'main'
<MainScreen@Screen>:
BoxLayout:
ScrollView:
GridLayout:
id: container_y
size_hint_y: None
cols: 2
row_default_height: root.height*0.3
height: self.minimum_height
Image:
source: "drink.png"
ImageButton:
source: 'drink.png'
on_release: app.root.current ="other"
size_hint_y: None
height: 40
ImageButton:
source: 'drink.png'
on_release: app.root.current ="other"
size_hint_y: None
height: 40
ImageButton:
source: 'drink.png'
on_release: app.root.current ="other"
size_hint_y: None
height: 40
ImageButton:
source: 'drink.png'
on_release: app.root.current ="other"
size_hint_y: None
height: 40
ImageButton:
source: 'drink.png'
on_release: app.root.current ="other"
size_hint_y: None
height: 40
"""
class ImageButton(ButtonBehavior, Image):
pass
class ImageButtonApp(App):
def build(self):
return Builder.load_string(kv)
ImageButtonApp().run()https://stackoverflow.com/questions/65463089
复制相似问题