<tfoot id='oVwRH'></tfoot>

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

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

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

        Scatter 大小和位置的问题

        时间:2023-10-09

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

            • <bdo id='PYh5X'></bdo><ul id='PYh5X'></ul>
            • <tfoot id='PYh5X'></tfoot>
                <tbody id='PYh5X'></tbody>
            • <legend id='PYh5X'><style id='PYh5X'><dir id='PYh5X'><q id='PYh5X'></q></dir></style></legend>

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

                  本文介绍了Scatter 大小和位置的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我遇到了一些与分散对象相关的问题.从我下面的代码.在我调整 Scatter (self.size_hint_x, self.size_hint_y = 0.3, 0.3) 的大小后,对象 (canvasScatter 中的 label) 也不会调整大小.我确实尝试将 size_hint=1 应用于 Scatter 内的 CanvasLabel,但结果仍然是一样.

                  I encountered some issue related to scatter object. From my codes below. After I resize a Scatter (self.size_hint_x, self.size_hint_y = 0.3, 0.3), the objects (canvas, label) inside the Scatter is not resized as well. I did tried to apply size_hint=1 to the Canvas and Label inside the Scatter, however the result still the same.

                  我遇到的另一个问题是检索 Canvas/Label 中的 X, Y 位置(相对于父级)分散.它总是给我(0,0).

                  Another issue I encountered is the retrieving of the X, Y position (relative to the parent) for the Canvas/Label in a Scatter. It always give me (0,0).

                  我的代码

                  from kivy.app import App
                  from kivy.core.window import Window
                  from kivy.uix.widget import Widget
                  from kivy.uix.floatlayout import FloatLayout
                  from kivy.uix.label import Label
                  from kivy.uix.scatter import Scatter
                  from kivy.graphics import Color, Rectangle, Canvas
                  
                  class Avatar(Scatter):
                      def __init__(self, **kwargs):
                          super(Avatar, self).__init__(size_hint=(None,None), **kwargs)
                  
                          with self.canvas:
                              Color(0, 0, 0)
                              Rectangle(pos=(self.x, self.y), size=(self.width, self.height))
                  
                          self.lbl = Label(text='Test', size_hint_x=1, size_hint_y=1)
                          self.add_widget(self.lbl)
                  
                          # Scatter size is 30% of the GameBackground
                          # ISSUE: After resize my Scatter, the objects inside is not resized as well.
                          self.size_hint_x, self.size_hint_y = 0.3, 0.3
                  
                  
                  class GameBackground(FloatLayout):
                      def __init__(self, **kwargs):
                          super(GameBackground, self).__init__(**kwargs)
                  
                          with self.canvas:
                              Color(1, 0, 1)
                              Rectangle(pos = (0, 0), size = (Window.width,Window.height))
                  
                          self.elf = Avatar()
                          self.add_widget(self.elf)
                          self.elf.x = 200
                          self.elf.y = 300
                  
                          # Get the X, Y position of the Scatter and the label inside the Scatter relative to the parent.
                          print self.elf.pos      #<-- This works.
                          print self.elf.lbl.pos  #<-- ISSUE: This not working.
                  
                  
                  class GameApp(App):
                      def build(self):
                          return GameBackground()
                  
                  
                  if __name__ == '__main__':
                      GameApp().run()
                  

                  我错过了什么吗?感谢您的任何建议.

                  Did I miss something? Thanks for any advise.

                  我是 Kivy 的新手.如果我的qns很笨,请原谅我.:P

                  推荐答案

                  您是否阅读了 分散.它说

                  ...特定的行为使分散变得独一无二,您应该考虑一些优点/限制:

                  ...specific behavior makes the scatter unique, and there are some advantages / constraints that you should consider:

                  1. 孩子的位置相对于 0, 0.分散位置对孩子的位置没有影响.
                  2. 这也适用于尺寸.如果要调整散点图的大小,请使用比例,而不是大小.(阅读 #1.)

                  这回答了你的第一个问题.它说使用比例,而不是大小.还有方法 apply_transform 您可能会发现它对其他转换很有用.虽然我从未尝试过这种方法,但我看不到平移值(我可以看到旋转和缩放)

                  That answer your first question. It says use scale, not size. There is also the the method apply_transform that you may find useful for other transformations. I have never tried this method though but I cannot see the translate value (I can see Rotate and Scale)

                  关于你的第二个问题.您在 self.xself.y 位置添加一个矩形,即 (0,0).因此,您的 Rectangle 处于该位置.如果您拖动(使用手指或鼠标)您的小部件.Rectangle 的位置仍然相对于 Scatter.因此,除非您更改 Rectangle 的位置(使用代码),否则它将始终位于 (0,0) 中.变换总是相对于 Scatter.

                  Regarding to your second question. You are adding a Rectangle in the self.x and self.y position that is (0,0). So, your Rectangle is in that position. If you drag (using your fingers or mouse) your widget. The position of the Rectangle remains relative to the Scatter. So, unless you change the position of the Rectangle (with code) it will be always be in the (0,0). The transformations are always relative to the Scatter.

                  这个question 可能是相关的,并解释了一些不使用 Kivy 语言添加顶点指令(即矩形)的问题.你应该考虑一下,因为你所做的似乎是相关的.

                  This question might be related and explains a few issues with not using the Kivy Language to add Vertex Instructions (i.e. Rectangles). You should consider it because what you are doing seems to be related.

                  * 编辑 - 根据我对您要达到的目标的理解进行必要的更正 *

                  1) 不要像您正在使用的那样使用尺寸提示.

                  1.1) 代替:

                  self.lbl = Label(text='Test', size_hint_x=1, size_hint_y=1)
                  

                  使用:

                  self.lbl = Label(text='Test', width=self.width, height=self.height)
                  

                  1.2) 并且,而不是:

                  1.2) And, instead of:

                  self.size_hint_x, self.size_hint_y = 0.3, 0.3
                  

                  使用:

                  self.scale = 0.3
                  

                  2) 位置是相对于散点的.因此,您需要将坐标转换给父级.

                  2) The position is relative to the scatter. Therefore you need to transale the coordinates to the parent.

                  2.1) 代替:

                  print self.elf.lbl.pos  #<-- ISSUE: This not working.
                  

                  使用:

                  print self.elf.to_parent(*self.elf.lbl.pos)
                  

                  完整代码如下:

                  from kivy.app import App
                  from kivy.core.window import Window
                  from kivy.uix.widget import Widget
                  from kivy.uix.floatlayout import FloatLayout
                  from kivy.uix.label import Label
                  from kivy.uix.scatter import Scatter
                  from kivy.graphics import Color, Rectangle, Canvas
                  
                  class Avatar(Scatter):
                      def __init__(self, **kwargs):
                          super(Avatar, self).__init__(size_hint=(None,None), **kwargs)
                  
                          with self.canvas:
                              Color(0, 0, 0)
                              Rectangle(pos=(self.x, self.y), size=(self.width, self.height))
                  
                          #self.lbl = Label(text='Test', size_hint_x=1, size_hint_y=1)
                          self.lbl = Label(text='Test', width=self.width, height=self.height)
                          self.add_widget(self.lbl)
                  
                          # Scatter size is 30% of the GameBackground
                          # ISSUE: After resize my Scatter, the objects inside is not resized as well.
                          # self.size_hint_x, self.size_hint_y = 0.3, 0.3
                          self.scale = 0.3
                  
                  
                  class GameBackground(FloatLayout):
                      def __init__(self, **kwargs):
                          super(GameBackground, self).__init__(**kwargs)
                  
                          with self.canvas:
                              Color(0, 0, 1)
                              Rectangle(pos = (0, 0), size = (Window.width,Window.height))
                  
                          self.elf = Avatar()
                          self.add_widget(self.elf)
                          self.elf.x = 200
                          self.elf.y = 300
                  
                          # Get the X, Y position of the Scatter and the label inside the Scatter relative to the parent.
                          print self.elf.pos      #<-- This works.
                          print self.elf.lbl.pos  #<-- ISSUE: This not working.
                          print self.elf.to_parent(*self.elf.lbl.pos)
                  
                  class GameApp(App):
                      def build(self):
                          return GameBackground()
                  
                  if __name__ == '__main__':
                      GameApp().run()
                  

                  这篇关于Scatter 大小和位置的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:引用 Kivy 中动态创建的小部件的 id 下一篇:将文本输入保存到 kivy 应用程序中的变量

                  相关文章

                  最新文章

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

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

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

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

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