Search code examples
pythonkivy

Kivy remove Popup overlay


I use Kivy Popup the following way:

<AlertPopup@Popup>:
    auto_dismiss: False
    title: "Notice"
    background: ''
    size_hint: (None,None)
    pos_hint: {'top': 0.9, 'right': 1.0}
    overlay_color: 0, 0, 0, 0.5
    background_color: 0, 0, 0, 0
    canvas.before:
        Color:
            rgba: 243, 253, 18, 0.48
        Rectangle:
            pos: self.pos[0], self.pos[1]
            size: self.size

    BoxLayout:
        orientation: 'vertical'
        BoxLayout:
            orientation: 'horizontal'
            Button:
                size_hint: .15, 1.0
                text: 'X'
                on_release: root.dismiss()
            Label:
                text: 'Some message here'

When the popup is shown, there is an overlay, for which the overlay_color: 0,0,0, 0.5 which I setup on purpose so I can see it. What I want, is for it to be removed, because when popup is shown I can't click on the rest of the application.

I'm using Python 3.9 and Kivy 2.1.0

enter image description here

I want to be able to click the area that surround the Popup(and there are clickable parts of the application behind that overlay).

Question: How can the overlay be removed completely?


Solution

  • I have used the wrong component for the job.

    I simply changed Popup to BoxLayout, and added a method like so:

    class AlertPopup(BoxLayout):
        def dismiss(self, *args):
            Window.remove_widget(self)
    

    Instead of using .open() to show it, simply use Window.add_widget(AlertPopup()), and from there the dismiss method above will remove itself from its parent.