Ajax1234
Ajax1234

Reputation: 71451

Changing Background of Kivy Popup

I have a popup window that I have built with kivy, but I cannot seem to change its background color from its default grey, although I have set the background_color object. Does anyone have any suggestions?

Here is my code:

class CAP(BoxLayout):

     def sPop(self):
          box = BoxLayout(background_color=(0, 255, 0, 0.8))

         closer = Button(
             text="Close",
             pos_hint={'x': 6, 'center_y': 0.04},
             size_hint=(0.1, 0.1),
             background_color=(0, 0, 255, 0.7)
         ) 
         box.add_widget(closer)

         box.add_widget(Label(text="", index=6))

         p = Popup(title = "", content = box, size=(25,   
     25))
         p.background_color=(0, 0, 255, 0.9)

         closer.bind(on_press=p.dismiss)
         p.open()

Upvotes: 1

Views: 1838

Answers (1)

Amin Etesamian
Amin Etesamian

Reputation: 3699

Use canvas context after you declared p

from kivy.graphics.context_instructions import Color
from kivy.graphics.vertex_instructions import Rectangle

def update_rect(instance, value):
    instance.rect.pos = instance.pos
    instance.rect.size = instance.size

with p.canvas.before:
    Color(0, 0.517, 0.705, 1)
    p.rect = Rectangle(size=content.size, pos=content.pos)
    p.bind(pos=update_rect, size=update_rect)

Upvotes: 1

Related Questions