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

    1. <tfoot id='upnlk'></tfoot>
        • <bdo id='upnlk'></bdo><ul id='upnlk'></ul>

        如何在 Kivy 的画布中引用孩子的 id?

        How do I reference id#39;s of children within a canvas in Kivy?(如何在 Kivy 的画布中引用孩子的 id?)
        <tfoot id='oGWbw'></tfoot>
        • <legend id='oGWbw'><style id='oGWbw'><dir id='oGWbw'><q id='oGWbw'></q></dir></style></legend>

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

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

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

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

                  问题描述

                  当我尝试将 id 分配给画布时,我收到错误 Invalid data after declaration,但我看不到任何其他引用该 id 的方式(例如 e1).如何在我的 Python 代码中引用 e1?

                  I get the error Invalid data after declaration when I try to assign an id to canvas, but I don't see any other way of referencing the id's further below (for example e1). How do I reference e1 in my Python code?

                  <MyClockWidget>:
                      face: face
                      ticks: ticks
                      el1: el1
                      FloatLayout:
                          id: face
                          size_hint: None, None
                          pos_hint: {"center_x":0.5, "center_y":0.5}
                          size: 0.9*min(root.size), 0.9*min(root.size)
                          canvas:
                              id: cand
                              Color:
                                  rgb: 0.5, 0.5, 0.5
                              Ellipse:
                                  size: self.size     
                                  pos: self.pos
                          canvas:
                              Color:
                                  rgb: 0.1, 0.1, 0.1
                              Ellipse:
                                  id: el1
                                  size: self.size     
                                  pos: self.pos
                                  angle_start: 0
                                  angle_end: 90
                              Ellipse:
                                  id: el2
                                  size: self.size     
                                  pos: self.pos
                                  angle_start: 110
                                  angle_end: 130
                  

                  推荐答案

                  我觉得用不到 instruction groups 有很好的文档记录,但这里有一个示例,说明如何使用它们以后访问 Canvas 元素.此示例还展示了如何使用属性来控制 Canvas 指令的各个方面:

                  I don't think the use of instruction groups in kv lang is well documented, but here is an example for how to use them to later access Canvas elements. This example also show how to use properties to control aspects of a Canvas instruction:

                  from kivy.app import App
                  from kivy.uix.slider import Slider
                  from kivy.lang import Builder
                  from kivy.graphics import Color
                  
                  kv = """
                  #:kivy 1.9.1
                  BoxLayout:
                      orientation: 'vertical'
                      Widget:
                          id: w_canvas
                          my_color: (0, 1, 1)
                          canvas:
                              Color:
                                  rgb: self.my_color
                              Rectangle:
                                  pos: self.pos
                                  size: (self.width/2, self.height/2)
                              Color:
                                  group: 'b'
                                  rgb: (0, .8, 0)
                              Ellipse:
                                  group: 'a'
                                  pos: (self.pos[0], self.pos[1] + self.height/2)
                                  size: (self.width/4, self.height/4)
                              Ellipse:
                                  group: 'b'
                                  pos: (self.pos[0]+ self.width/2, self.pos[1] + self.height/2)
                                  size: (self.width/4, self.height/4)
                      Button:
                          text: 'Click me'
                          on_release: app.handle_button()
                  """
                  class Test(App):
                      def build(self):
                          return Builder.load_string(kv)
                      def handle_button(self):
                          # binding Canvas instruction property to Widget property
                          self.root.ids.w_canvas.my_color = (.5, .2, 0)
                          # Access single item of canvas instruction group
                          an_ellipse = self.root.ids.w_canvas.canvas.get_group('a')[0]
                          an_ellipse.pos = (an_ellipse.pos[0] + 10, an_ellipse.pos[1])
                          # loop through all elements of canvas instruction group
                          for gitem in self.root.ids.w_canvas.canvas.get_group('b'):
                              if isinstance(gitem, Color):
                                  gitem.rgb = (0, .5, 1)
                              try:
                                  gitem.size = (gitem.size[0] / 2.0, gitem.size[1])
                              except:
                                  pass
                  
                  Test().run()
                  

                  这篇关于如何在 Kivy 的画布中引用孩子的 id?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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中更改按钮或标签文本颜色)

                  <legend id='E5gw2'><style id='E5gw2'><dir id='E5gw2'><q id='E5gw2'></q></dir></style></legend>

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

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

                        <tbody id='E5gw2'></tbody>

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