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

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

      1. 在 Kivy 中更改按钮的背景颜色

        时间:2023-10-10
        • <tfoot id='UzTrB'></tfoot>

            <tbody id='UzTrB'></tbody>
            <legend id='UzTrB'><style id='UzTrB'><dir id='UzTrB'><q id='UzTrB'></q></dir></style></legend>

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

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

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

                2. 本文介绍了在 Kivy 中更改按钮的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我是 Kivy 的新手,无法指定按钮的背景颜色.这是我的简单示例:

                  I'm new to Kivy and having trouble specifying the background color of a Button. Here's my simple example:

                  # custombutton.py
                  
                  from kivy.app import App
                  from kivy.uix.widget import Widget
                  
                  
                  class MyWidget(Widget):
                      pass
                  
                  
                  class CustomButtonApp(App):
                      def build(self):
                          return MyWidget()
                  
                  
                  if __name__ == '__main__':
                      CustomButtonApp().run()
                  

                  以及随附的kv文件custombutton.kv:

                  #:kivy 1.7.2
                  
                  <MyWidget>:
                      canvas:
                          Color:
                              rgb: (0.93, 0.93, 0.93)
                          Rectangle:
                              pos: self.pos
                              size: self.size
                  
                      Button:
                          center: self.parent.center
                          font_size: 14
                          height: 28
                          background_color: (1.0, 0.0, 0.0, 1.0)
                          text: "I'm a Button"
                  

                  我确定我遗漏了一些明显的东西,但我已经搞砸了一个多小时,却一无所获.该按钮似乎被染成了深红色:

                  I'm sure I'm missing something obvious, but I've been messing with this for over an hour now and getting nowhere. The button seems to get colored a hint of very dark red:

                  这不是为 Kivy 中的按钮指定背景颜色的方法吗?

                  Is this not the way to specify the background color for a Button in Kivy?

                  谢谢!

                  推荐答案

                  啊,这是一个常见的混淆.问题是 Button.background_color 确实是一种 tint,而不仅仅是块颜色.由于默认背景是灰色图像(您通常会在制作无样式按钮时看到该图像),因此您最终看到的是该灰色图像的红色调 - 您观察到的暗红色.

                  Ah, this is a common confusion. The problem is that Button.background_color really works as a kind of tint, not just a block colour. Since the default background is a grey image (the one you normally see if you make an unstyled button), what you end up seeing is a red tint to that grey image - which comes out as the dark red you observe.

                  您可以通过将背景图像替换为纯白色(不必超过几个像素)或使用 background_normal 来获得所需的行为和 background_down 属性.当您的 background_color 为新的纯白色图像着色时,您将获得所需的纯红色.

                  You can get the behaviour you want by replacing the background image to just one that's plain white (it doesn't have to be more than a few pixels), or by otherwise playing with the background_normal and background_down properties. When your background_color tints the new pure white image, you get the pure red you're after.

                  我想这在文档中不是很清楚,我会尝试改进它.

                  I guess this isn't so clear in the docs, I'll try to improve it.

                  这篇关于在 Kivy 中更改按钮的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:您如何使用 kivy 检查键盘事件? 下一篇:用kivy制作时钟

                  相关文章

                  最新文章

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

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

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

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