1. <tfoot id='CqY3H'></tfoot>

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

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

  2. <legend id='CqY3H'><style id='CqY3H'><dir id='CqY3H'><q id='CqY3H'></q></dir></style></legend>
    <i id='CqY3H'><tr id='CqY3H'><dt id='CqY3H'><q id='CqY3H'><span id='CqY3H'><b id='CqY3H'><form id='CqY3H'><ins id='CqY3H'></ins><ul id='CqY3H'></ul><sub id='CqY3H'></sub></form><legend id='CqY3H'></legend><bdo id='CqY3H'><pre id='CqY3H'><center id='CqY3H'></center></pre></bdo></b><th id='CqY3H'></th></span></q></dt></tr></i><div id='CqY3H'><tfoot id='CqY3H'></tfoot><dl id='CqY3H'><fieldset id='CqY3H'></fieldset></dl></div>
    1. Kivy:如何将画布用于在 python 中创建的小部件

      Kivy: how to use canvas for widgets created in python(Kivy:如何将画布用于在 python 中创建的小部件)
        <legend id='rB2RP'><style id='rB2RP'><dir id='rB2RP'><q id='rB2RP'></q></dir></style></legend>
      • <tfoot id='rB2RP'></tfoot>

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

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

                本文介绍了Kivy:如何将画布用于在 python 中创建的小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想在我的复选框中添加一个画布来更改它们的颜色.我找到了这个答案,但我正在努力实现它.我的复选框是使用以下代码在 python 中创建的:

                I would like to add a canvas to my checkboxes to change their color. I have found this answer, but I am struggling to implement it. My checkboxes are created in python with this code:

                checkb= CheckBox()
                layout.add_widget(checkb)
                

                尝试 1:我尝试了 这里但没有成功:

                Attempt 1: I tried the solution from here but without success:

                checkb= CheckBox()
                checkb.canvas.add(Color(1., 1., 0))
                checkb.canvas.add(Rectangle(size=(50, 50)))
                layout.add_widget(checkb)
                

                尝试 2:我还尝试在构建器中创建一个自定义复选框,但没有找到使其工作的方法(我找不到有关这种设置的任何信息,所以我不确定甚至可以让它工作):

                Attempt 2: I also tried to come up with a custom checkbox created in the builder but didn't find a way to make it work (I couldn't find any info about this kind of setup, so I am not sure it's even possible to make it work):

                Builder.load_string('''
                <CustomCk@CheckBox>:
                    canvas.before:
                        Color:
                            rgb: 1,0,0
                        Rectangle:
                            pos:self.center_x-8, self.center_y-8
                            size:[16,16]
                        Color:
                            rgb: 0,0,0
                        Rectangle:
                            pos:self.center_x-7, self.center_y-7
                            size:[14,14]                
                
                ''')
                

                checkb= CustomCk()
                layout.add_widget(checkb)
                

                <小时>

                我尝试使用 with 语句:


                Edit : my try with the with statement:

                checkb= CheckBox()  
                with checkb.canvas:
                    Color(1, 2, 0)
                    Rectangle(size=(50, 50))
                layout.add_widget(checkb)
                

                推荐答案

                你应该使用 Python 代码中的 with 语句

                You should use the with statement from your python code

                with checkb.canvas:
                    Color(1., 1., 0)
                    Rectangle(size=(50, 50))
                

                您的其他方法似乎更好,只需稍微修复一下:

                Your other approach seems better, just fix it a bit:

                Builder.load_string('''
                <CustomCk>:
                    canvas.before:
                        Color:
                            rgb: 1,0,0
                        Rectangle:
                            pos:self.center_x-8, self.center_y-8
                            size:[16,16]
                        Color:
                            rgb: 0,0,0
                        Rectangle:
                            pos:self.center_x-7, self.center_y-7
                            size:[14,14]                
                
                    ''')
                
                class CustomCk(CheckBox): #define the class in the python file... 
                     pass
                
                checkb= CustomCk()
                layout.add_widget(checkb)
                

                这篇关于Kivy:如何将画布用于在 python 中创建的小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Kivy 1.9.0 Windows package KeyError: #39;rthooks#39;(Kivy 1.9.0 Windows 包 KeyError: rthooks)
                Python Kivy: how to call a function on button click?(Python Kivy:如何在按钮单击时调用函数?)
                How to disable a widget in Kivy?(如何禁用 Kivy 中的小部件?)
                Centering an object in Kivy(在 Kivy 中将对象居中)
                How to downgrade to Python 3.4 from 3.5(如何从 Python 3.5 降级到 Python 3.4)
                Change button or label text color in kivy(在kivy中更改按钮或标签文本颜色)
                    <tbody id='OYSMX'></tbody>
                • <small id='OYSMX'></small><noframes id='OYSMX'>

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

                    <tfoot id='OYSMX'></tfoot>
                    <legend id='OYSMX'><style id='OYSMX'><dir id='OYSMX'><q id='OYSMX'></q></dir></style></legend>

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