我想通过多个不同的按钮显示单个图像(如图https://i.stack.imgur.com/BQ99R.jpg所示)
当我尝试这样做时,图像被按钮覆盖并隐藏在背景中。
我想知道的是,这在奇异鸟身上有可能吗?如果是,我应该在标签或按钮的哪里定义图像?
答案 0 :(得分:2)
此代码:
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.lang import Builder
Builder.load_string("""
<Base>:
GridLayout:
cols: 2
size_hint: 1, 1
Button:
text: "Button 1"
on_press: print(self.text)
Button:
text: "Button 2"
on_press: print(self.text)
Button:
text: "Button 3"
on_press: print(self.text)
Button:
text: "Button 4"
on_press: print(self.text)
Image:
source: 'wolf.png'
""")
class Base(FloatLayout):
def __init__(self, **kwargs):
super(Base, self).__init__(**kwargs)
class SampleApp(App):
def build(self):
return Base()
if __name__ == "__main__":
SampleApp().run()
当然,您必须自己提供图片; o)