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

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

        <bdo id='QZq2K'></bdo><ul id='QZq2K'></ul>
      <legend id='QZq2K'><style id='QZq2K'><dir id='QZq2K'><q id='QZq2K'></q></dir></style></legend>
    2. <i id='QZq2K'><tr id='QZq2K'><dt id='QZq2K'><q id='QZq2K'><span id='QZq2K'><b id='QZq2K'><form id='QZq2K'><ins id='QZq2K'></ins><ul id='QZq2K'></ul><sub id='QZq2K'></sub></form><legend id='QZq2K'></legend><bdo id='QZq2K'><pre id='QZq2K'><center id='QZq2K'></center></pre></bdo></b><th id='QZq2K'></th></span></q></dt></tr></i><div id='QZq2K'><tfoot id='QZq2K'></tfoot><dl id='QZq2K'><fieldset id='QZq2K'></fieldset></dl></div>
      1. BoxLayout 中的两个 kivy 图像

        时间:2023-10-09
          <tbody id='OLbCj'></tbody>

          1. <small id='OLbCj'></small><noframes id='OLbCj'>

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

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

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

                • 本文介绍了BoxLayout 中的两个 kivy 图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我试图用两张图片制作一个 kivy 程序,当我点击它们时它们应该会改变.但是当我试图将两个包含图像的小部件添加到 BoxLayout 时,我在位置 0、0 处得到了一个图像为什么 BoxLayout 不适用于我的图像?这是我的代码:

                  I tried to make an kivy program wit two images , which are supposed to change when I click on them. But when I tred to add two Widgets with the containing Images to an BoxLayout, I got one image at the position 0, 0 Why dosen't the BoxLayout work with my images? Here is my code:

                  from kivy.app import App
                  from kivy.uix.widget import Widget
                  from kivy.lang import Builder
                  from kivy.core.window import Window
                  from kivy.properties import NumericProperty
                  from kivy.properties import StringProperty
                  from kivy.uix.button import Button
                  from kivy.uix.boxlayout import BoxLayout
                  
                  class Feld(Widget):
                      droga = StringProperty('hinterg.png')
                      kr = StringProperty('kreuz.png')
                      ks = StringProperty('kreis.png')
                      def on_touch_down(self, touch):
                          if self.collide_point(*touch.pos):
                              self.droga = self.kr
                  
                  root = Builder.load_string('''
                  BoxLayout:
                      orientation: 'horizontal'
                      Feld:
                          id: a1
                      Feld:
                          id: a2
                  
                  <Feld>:
                      Image:
                          source: root.droga
                  
                  
                  
                  ''')
                  
                  class app(App):
                      def build(self):
                          Window.clearcolor = (0, 0.54, 1, 1)
                          return root
                  
                  if __name__ == "__main__":
                      app().run()
                  

                  推荐答案

                  您的 Feld 实例由 BoxLayout 定位,但图像显示在作为 Feld 子级的 Image 小部件中.由于 Feld 只是一个普通的 Widget,它不会对其子级施加任何自动位置或大小,因此两个实际图像的默认大小为 (100, 100),位置为 (0, 0).

                  Your Feld instances are positioned by the BoxLayout, but the image is displayed in an Image widget that is a child of the Feld. Since Feld is just a normal Widget, it doesn't impose any automatic position or size on its children, so both actual images have the default size of (100, 100) and pos of (0, 0).

                  最好的解决方案是让 Feld 成为一些布局的子类,默认情况下它的子级会填充自己,例如 FloatLayout.

                  The best solution is to make Feld a subclass of some layout that will make its child fill itself by default, such as a FloatLayout.

                  这篇关于BoxLayout 中的两个 kivy 图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在 Kivy 中自定义 style.kv 下一篇:Kivy - 创建新的小部件并设置其位置和大小

                  相关文章

                  最新文章

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

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

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