Kivy: Code Popup Dismiss Button in KV Language

Viewed 4460

I'm trying to code a custom popup in kivy for picking a color from the ColorPicker widget. Right now i'm trying to hook up an 'OK' button to dismiss the popup, but it's not working. The popup up displays correctly, but when i click OK, nothing happens. The popup continues on screen.

Here's my python code.

from kivy.app import App
from kivy.uix.popup import Popup
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.colorpicker import ColorPicker

class PaintWindow(BoxLayout):
    pass

class CPopup(Popup):
    def on_press_dismiss(self, *args):
        self.dismiss()
        return False

class PixPaint(App):
    def build(self):
        pw = PaintWindow()
        return pw

if __name__ == '__main__':
    PixPaint().run()

Here's the KV code.

<PaintWindow>:
    orientation: 'vertical'
    CPopup:

<CPopup>:
    title: 'Pick a Color'
    size_hint: 1.0, 0.6
    id: cpopup

    BoxLayout:
        orientation: 'vertical'

        ColorPicker:
            size_hint: 1.0, 1.0

        Button:
            text: 'OK'
            size_hint: 1.0, 0.2
            on_press: cpopup.on_press_dismiss()

Any help is much appreciated. Sorry for all the code! :)

1 Answers
Related