kivy:将背景颜色更改为白色 [英] kivy: change background color to white

查看:40
本文介绍了kivy:将背景颜色更改为白色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个带有黑色按钮和标签以及带有白色文本的应用程序,因此,我希望用空白空间分隔这些小部件.我想为了做到这一点,有必要将背景从默认颜色(黑色)转换为白色.实现这一目标的最佳方法是什么?谢谢!

I'd like to have an app with black buttons and labels, and with white text, and thus, would like to have white space separating these widgets. I suppose that in order to do so, it would be necessary to convert the background from the default color, which is black, to white. What is the best way of accomplishing this? Thank you!

推荐答案

一种简单的方法是在根窗口小部件后面简单地绘制一个大的白色矩形.例如,在 kivy 语言中,您可以这样做

A simple way is to simply draw a big white rectangle behind your root widget. For instance, in kivy language you could do

<YourRootWidget>:
    canvas.before:
        Color:
            rgba: 1, 1, 1, 1
        Rectangle:
            pos: self.pos
            size: self.size

我认为您实际上也可以直接设置kivy清除窗口背景的颜色,该颜色显示为Window.clearcolor.你会这样做

I think you can also actually directly set the colour that kivy clears the window background with, which is exposed as Window.clearcolor. You would do this with

from kivy.core.window import Window
Window.clearcolor = (1, 1, 1, 1)

您可能需要将它放在应用程序中的任何其他内容之前,因为如果在创建窗口后运行它不会影响任何内容.

You would probably need to put this before anything else in your app, as it won't affect anything if run after the window has been created.

这篇关于kivy:将背景颜色更改为白色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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