python-如何在猕猴桃中更改弹出窗口的颜色

时间:2018-09-07 08:03:04

标签: python python-2.7 kivy

我正在使用python-2.7kivy。我正在使用Popup小部件。默认情况下,弹出窗口显示为灰色。
在我添加self.background = " "之后,弹出窗口颜色变为白色,但是如何变为白色以外的另一种颜色。

test.py

from kivy.app import App
from kivy.core.window import Window
from kivy.uix.popup import Popup

class Pop(Popup):
    def __init__(self, **kwargs):
        super(Pop, self).__init__(**kwargs)
        self.background = ""
        self.open()


class TestApp(App):
    def build(self):
        return Pop()


TestApp().run()

1 个答案:

答案 0 :(得分:1)

background:设置为图片文件( jpeg,jpg,gif,png )。在示例中,我们使用 yellow.png 文件。

示例

main.py

from kivy.app import App
from kivy.uix.popup import Popup
from kivy.uix.button import Button
from kivy.lang import Builder


Builder.load_string('''
#:kivy 1.11.0

<abc>:
    title : "change title color"
    title_color: 1, 0, 0, 1    # red title

    background: 'yellow.png'

    BoxLayout:
        orientation: "vertical"

        GridLayout:
            cols: 1
            Label:
                bold: True
                text: "make label bold"
                color: 1, 0, 0, 1    # red color text

            Label:
                markup: True
                text: "[b][color=008000]make[/color] label [color=3333ff]bold[/color][/b]"

''')


class abc(Popup):
    pass


class PopupApp(App):
    title = 'Popup Demo'

    def build(self):
        self._popup = abc()
        return Button(text="press me", on_press=self._popup.open)


PopupApp().run()

输出

Img01