繁体   English   中英

在多个按钮上显示图像 - kivy

[英]Displaying an image over multiple buttons - kivy

我想在多个不同的按钮上显示单个图像(如图所示: https : //i.stack.imgur.com/BQ99R.jpg

当我尝试这样做时,图像被按钮覆盖并隐藏在背景中。

我想知道的是,这在 kivy 中甚至可能吗? 如果是,我在哪里定义图像,在标签或按钮中?

这段代码:

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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM