• <small id='w31Ie'></small><noframes id='w31Ie'>

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

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

      1. Kivy:如何将画布用于在 python 中创建的小部件

        时间:2023-10-10

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

          <small id='9Q5XT'></small><noframes id='9Q5XT'>

                  <bdo id='9Q5XT'></bdo><ul id='9Q5XT'></ul>
                  <tfoot id='9Q5XT'></tfoot><legend id='9Q5XT'><style id='9Q5XT'><dir id='9Q5XT'><q id='9Q5XT'></q></dir></style></legend>

                    <tbody id='9Q5XT'></tbody>
                • 本文介绍了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 中创建的小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:向 Windows 添加“DEBUG=1"命令? 下一篇:Python/Kivy AttributeError:“超级"对象没有属性“

                  相关文章

                  最新文章

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

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

                    • <bdo id='PwLRy'></bdo><ul id='PwLRy'></ul>
                    1. <legend id='PwLRy'><style id='PwLRy'><dir id='PwLRy'><q id='PwLRy'></q></dir></style></legend>