在猕猴桃中制作背景画布 [英] Making a background canvas in kivy

查看:74
本文介绍了在猕猴桃中制作背景画布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了有关如何在Kivy中更改背景,添加颜色等问题,并且我熟悉如何对小部件进行操作.

I've read the questions about how to change a background, add a color, etc. in Kivy, and I'm familiar with how to do that for widgets.

我的问题是一种通用策略,当我想要的是要放置其他小部件的背景(应该是标签或小部件)时,打算使用哪种对象?或布局? (假设我只有一个小的填充背景,我将在其上放置不同的彩色网格布局,如

My question is sort of a general strategy of what sort of object is intended to be used when all I want is a background that I'm going to put other widgets on---should that be a label or a widget, or a layout? (Suppose I'm only going to have a small padded background that I'll put a different colored gridlayout on, as in this question.)

推荐答案

我认为答案确实是取决于"的.如您所说,您可以为任何内容添加背景,因此决定完全取决于您希望小部件具有哪种其他行为.

I think the answer is really 'it depends'. As you say, you can add a background to anything, so the decision rests entirely on what kind of other behaviour you want the widget to have.

我想要的是一个背景,要放置其他小部件—应该是标签,小部件还是布局?

all I want is a background that I'm going to put other widgets on---should that be a label or a widget, or a layout?

如果您完全不希望有任何额外的行为,则Widget就可以了.如果您想要简单的行为,例如让孩子自动放置/调整大小以填充背景小部件,那么当然,像BoxLayout这样的简单布局将是理想的选择.或者,您可能希望(例如)使子对象的尺寸比背景小部件的尺寸小一点,以得到一个较小的边框,在这种情况下,AnchorLayout恰好是正确的.或者对于任意比例行为,FloatLayout是理想的.

If you want totally no extra behaviour, a Widget is fine. If you want simple behaviour like having the child automatically placed/size to fill the background widget, then of course a simple layout like BoxLayout will be ideal. Alternatively, you might want (for instance) the child to be made a little smaller than the background widget in order to get a little border, in which case an AnchorLayout would be just right. Or for arbitrary proportional behaviour, the FloatLayout is ideal.

当然您可以在这里看到,问题实际上归结为您是否想要布局行为",如果是的话,您只需选择满足您需求的布局即可.绝对没有限制和规则,在kivy的设计中,您可以组合这样的行为以精确地获得所需的内容.

Of course you can see there, the question really comes down to 'do you want layout behaviour', and if so you just pick the layout that does what you want. There's absolutely no limitation and rule, and it's in the design of kivy that you can combine behaviours like this to get precisely what you want.

(假设我只会有一个小的填充背景,像这个问题一样,我会在上面加上不同的彩色网格布局.)

(Suppose I'm only going to have a small padded background that I'll put a different colored gridlayout on, as in this question.)

在这种情况下, AnchorLayout 似乎很理想.这使您可以为子窗口小部件设置填充,但是(默认情况下)它会居中放置,因此,如果您使用背景制作自己的AnchorLayout子类,则会得到您想要的边框.

In this case, an AnchorLayout seems ideal. This lets you set a padding for the child widget, but (by default) it's otherwise centered, so if you make your own AnchorLayout subclass with a background you'll get the border you seem to want.

这篇关于在猕猴桃中制作背景画布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆