gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 02:00:06 24 4
gpt4 key购买 nike

我想在多个不同的按钮上显示单个图像(如图所示:/image/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()

产生这个: enter image description here

当然你必须自己提供一张图片;o)

关于python - 在多个按钮上显示图像 - kivy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55888058/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com