Search code examples
pythonkivy

How to change popup color in kivy


In Kivy, Popup appears in grey color, what should be changed to make it red color

My popup code:

class MyPopup(Popup):
    def show_popup(self):
        content = BoxLayout(orientation="vertical")
        content.add_widget(Label(text="Game Over", font_size=20))
        mybutton_cancel = Button(text="Cancel", size_hint_y=None)
        content.add_widget(mybutton_cancel)

        mypopup = Popup(content = content,              
            title = "oops", 
            auto_dismiss = False,         
            size_hint = (.5, .5))
        mybutton_cancel.bind(on_release=mypopup.dismiss)
        mypopup.open()

I hope , it is clear that i am talking about popup color and not color of background screen behind popup or popup text color. I am talking about the color of popup rectangle. Please advice.


Solution

  • Popup as a child of ModalView has a StringProperty called background, which points to an image from at atlas. The default one is atlas://data/images/defaulttheme/modalview-background. Here I changed it to one of the default button images:

    from kivy.app import App
    from kivy.uix.button import Button
    from kivy.uix.popup import Popup
    from kivy.uix.label import Label
    
    class TestApp(App):
        def build(self):
            return  Button(text="show", on_press=self.anim_btn)
    
        def anim_btn(self, *args):
            popup = Popup(title='Test popup', 
                content=Label(text='Hello world'), 
                size_hint=(None, None), 
                size=(400, 400),
                background = 'atlas://data/images/defaulttheme/button_pressed'
            ).open()
    
    if __name__ == "__main__":
        TestApp().run()
    

    This default theme resides here: https://github.com/kivy/kivy/blob/master/kivy/data/images/defaulttheme-0.png In order to customize your popup (and also, for example, buttons) you can create your own atlas (http://kivy.org/docs/api-kivy.atlas.html).