Search code examples
pythonpython-2.7kivy

python - How to change popup color in kivy


I am using python-2.7 and kivy.I am using Popup widget. By default Popup appears in grey color.
After i add self.background = " " then popup color changed into white color But how to change into another color Apart from white.

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()

Solution

  • Set background: to picture file (jpeg, jpg, gif, png). In the example, we are using yellow.png file.

    Example

    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()
    

    Output

    Img01