编程语言
首页 > 编程语言> > python-Kivy:KV语言中的代码弹出窗口关闭按钮

python-Kivy:KV语言中的代码弹出窗口关闭按钮

作者:互联网

我正在尝试为自定义弹出式窗口编写代码,以便从ColorPicker小部件中选择一种颜色.现在,我正在尝试挂钩一个“确定”按钮以关闭弹出窗口,但是它不起作用.弹出窗口显示正确,但是当我单击“确定”时,什么也没有发生.弹出窗口在屏幕上继续.

这是我的python代码.

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

这是KV代码.

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

任何帮助深表感谢.对不起,所有代码!

标签:kivy,ubuntu-12-04,python
来源: https://codeday.me/bug/20191030/1964794.html