<tfoot id='xtcyv'></tfoot>
      <bdo id='xtcyv'></bdo><ul id='xtcyv'></ul>

    <small id='xtcyv'></small><noframes id='xtcyv'>

      <i id='xtcyv'><tr id='xtcyv'><dt id='xtcyv'><q id='xtcyv'><span id='xtcyv'><b id='xtcyv'><form id='xtcyv'><ins id='xtcyv'></ins><ul id='xtcyv'></ul><sub id='xtcyv'></sub></form><legend id='xtcyv'></legend><bdo id='xtcyv'><pre id='xtcyv'><center id='xtcyv'></center></pre></bdo></b><th id='xtcyv'></th></span></q></dt></tr></i><div id='xtcyv'><tfoot id='xtcyv'></tfoot><dl id='xtcyv'><fieldset id='xtcyv'></fieldset></dl></div>
    1. <legend id='xtcyv'><style id='xtcyv'><dir id='xtcyv'><q id='xtcyv'></q></dir></style></legend>
    2. 在 Kivy 中将图像对象作为按钮背景传递

      时间:2023-10-10
      <legend id='NOs5J'><style id='NOs5J'><dir id='NOs5J'><q id='NOs5J'></q></dir></style></legend>

      <i id='NOs5J'><tr id='NOs5J'><dt id='NOs5J'><q id='NOs5J'><span id='NOs5J'><b id='NOs5J'><form id='NOs5J'><ins id='NOs5J'></ins><ul id='NOs5J'></ul><sub id='NOs5J'></sub></form><legend id='NOs5J'></legend><bdo id='NOs5J'><pre id='NOs5J'><center id='NOs5J'></center></pre></bdo></b><th id='NOs5J'></th></span></q></dt></tr></i><div id='NOs5J'><tfoot id='NOs5J'></tfoot><dl id='NOs5J'><fieldset id='NOs5J'></fieldset></dl></div>
    3. <tfoot id='NOs5J'></tfoot>
        <tbody id='NOs5J'></tbody>

                <bdo id='NOs5J'></bdo><ul id='NOs5J'></ul>

                <small id='NOs5J'></small><noframes id='NOs5J'>

                本文介绍了在 Kivy 中将图像对象作为按钮背景传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                在 Kivy 中,有没有办法将图像对象作为按钮背景传递,而不是图像文件名?

                In Kivy, is there a way to pass image object as a button background, instead of image file name?

                button.background_normal 属性只接受字符串.我想自定义图像属性,例如 allow_stretch = False.

                button.background_normal property accepts only strings. I would like to customize image properties, such as allow_stretch = False.

                如果成功,我如何在按钮内指定图像对齐方式,例如.让它左上对齐?

                If that succeeds, how can I specify image alignment inside a button, eg. to make it top-left aligned?

                推荐答案

                source 只是 Button 的一个属性,正如你所指出的,它是一个字符串.你想要一个 Widget 里面有一个 Widget,这就是 Kivy 工作的基本方式.所以只需按原样添加图像.一点定位就可以完成剩下的工作.

                The source is just a property of Button and it is a string as you pointed out. You want a Widget inside a Widget, and that is the basic way Kivy works. So just add the Image as it is. A little bit of positioning would do the rest.

                你必须小心定位.确保它位于可见部分并且没有任何东西覆盖它.我在按钮后使用标签,因为它具有透明颜色,因此您可以尝试使用它.例如,如果您的定位错误(尝试 x:0 y:0),您可以看到按钮转到标签区域的左下角.

                You have to be careful with the positioning. Make sure it is in a visible part and nothing covers it. I use a Label after the button because it has transparent Color so you can experimenting with it. For example if your positioning is wrong (try x:0 y:0) you can see the button going to the bottom-left corner in the label area.

                我使用的图片是 Kivy 标志:

                from kivy.app import App
                from kivy.uix.boxlayout import BoxLayout
                from kivy.lang import Builder
                
                Builder.load_string("""
                <ButtonsApp>:
                    orientation: "vertical"
                    Button:
                        text: "B1"
                        Image:
                            source: 'kivy.png'
                            y: self.parent.y + self.parent.height - 250
                            x: self.parent.x
                            size: 250, 250
                            allow_stretch: True
                    Label:
                        text: "A label"
                """)
                
                class ButtonsApp(App, BoxLayout):
                    def build(self):
                        return self
                
                if __name__ == "__main__":
                    ButtonsApp().run()
                

                这篇关于在 Kivy 中将图像对象作为按钮背景传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:Python/Kivy:从一个类调用函数到另一个类并在 Pyt 下一篇:切换 kivy 小部件

                相关文章

                最新文章

                <i id='YSGpr'><tr id='YSGpr'><dt id='YSGpr'><q id='YSGpr'><span id='YSGpr'><b id='YSGpr'><form id='YSGpr'><ins id='YSGpr'></ins><ul id='YSGpr'></ul><sub id='YSGpr'></sub></form><legend id='YSGpr'></legend><bdo id='YSGpr'><pre id='YSGpr'><center id='YSGpr'></center></pre></bdo></b><th id='YSGpr'></th></span></q></dt></tr></i><div id='YSGpr'><tfoot id='YSGpr'></tfoot><dl id='YSGpr'><fieldset id='YSGpr'></fieldset></dl></div>

                <small id='YSGpr'></small><noframes id='YSGpr'>

                • <bdo id='YSGpr'></bdo><ul id='YSGpr'></ul>

                <legend id='YSGpr'><style id='YSGpr'><dir id='YSGpr'><q id='YSGpr'></q></dir></style></legend>
                  1. <tfoot id='YSGpr'></tfoot>