How to change popup color in kivy

喜欢而已 提交于 2021-02-08 06:57:21

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/30141937/how-to-change-popup-color-in-kivy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!