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

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

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

      Kivy:如何使小部件表现得像溢出:隐藏

      Kivy: How to make widget behave like overflow:hidden(Kivy:如何使小部件表现得像溢出:隐藏)
        • <bdo id='qA948'></bdo><ul id='qA948'></ul>

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

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

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

              • 本文介绍了Kivy:如何使小部件表现得像溢出:隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想在 Kivy 中创建带有许多矩形按钮的 GridLayout,其中包含一些不同大小的自定义图像.为此,我想缩放图像(我想这样做的方式如下所示),然后裁剪/隐藏溢出小部件边框的部分.调整大小效果很好,但我不知道如何隐藏/裁剪矩形之外的部分.例如:如果小部件的尺寸为 10 像素 x 10 像素,而我的图像为 100 像素 x 200 像素,我会将其调整为 10 像素 x 20 像素并在小部件中居中,但下方和上方的 5 像素将可见.我不要那个.:) 云有人帮我解决这个问题吗?

                I want to create GridLayout in Kivy with many rectangle buttons with some custom images with different size. To do so, I want to scale image (the way I wan to do this is shown below) and then crop/hide the parts that overflow the widget borders. The resizing works nice, but I can not figure out how to hide/crop that parts which are outside the rectangle. For example: if widget have dimensions of 10px x 10px and my image is 100px x 200px I will rezise it to 10px x 20px and center it in widget, but the 5px below and abowe will be visible. I do not want that. :) Cloud somebody help me with this problem?

                class PlaceIcon(Widget):
                    def __init__(self,image_path, **kwargs):
                        super(PlaceIcon, self).__init__(**kwargs)
                        self.bind(size=self.adjust_size)
                        self.image = Image(source=image_path)
                        self.image_path = image_path  
                
                    def adjust_size(self,*args):
                        (a,b) = self.image.texture.size
                        (x,y) = self.size
                        (x1,y1) = self.pos
                        if x > y:
                            scale = x/a
                        else:
                            scale = y/b
                        x1 -= (scale*a-x)/2
                        y1 -= (scale*b-y)/2
                        with self.canvas:
                            self.canvas.clear()
                            self.background = Rectangle(texture=self.image.texture, pos=(x1,y1), size=(scale*a,scale*b))
                

                推荐答案

                我会说看看Texture.get_region:http://kivy.org/docs/api-kivy.graphics.texture.html#kivy.graphics.texture.Texture.get_region

                I would say to look at Texture.get_region: http://kivy.org/docs/api-kivy.graphics.texture.html#kivy.graphics.texture.Texture.get_region

                因此,您可以只使用要显示和传递的纹理部分,就好像它是完全不同的纹理一样.

                So you can use only the part of the texture you want to display and passing as if it was an entirely different texture.

                另一种方法是使用 StencilView,但我认为这里的 get_region 更好.

                Another way would be to use StencilView, but i think here the get_region is better.

                这篇关于Kivy:如何使小部件表现得像溢出:隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                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中更改按钮或标签文本颜色)
                  • <small id='q6tv4'></small><noframes id='q6tv4'>

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

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