色の選択

2016/02/21

Python2.7.10, Kivy1.9.1

ポップアップで色選択画面が立ち上がるサンプル

# -*- coding: utf-8 -*-

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

from kivy.lang import Builder
Builder.load_string("""
<MyApp>:
    AnchorLayout:
        anchor_x: 'center'
        anchor_y: 'center'

        Button:
            text: 'Open ColorPicker'
            size: 300,100
            size_hint: None, None
            on_press: app.openPopup()

<MyPopup>:
    title: 'Color Select'
    size_hint: None, None
    size: 400, 400

    BoxLayout:
        orientation: 'vertical'
        ColorPicker:
            id: picker

        Button:
            size_hint_y: None
            height: 60
            text: 'Change'
            on_press: root.change_background_color()

""")

class MyPopup(Popup):

    def __init__(self,**args):
        super(MyPopup,self).__init__(**args)

    def change_background_color(self):
        Window.clearcolor = tuple( self.ids.picker.color )
        self.dismiss()


class MyApp(App, BoxLayout):

    def openPopup(self):
        popup = MyPopup()
        popup.open()

    def build(self):
        return self

if __name__ == "__main__":
    MyApp().run()


Color Picker — Kivy 1.9.2-dev0 documentation
https://kivy.org/docs/api-kivy.uix.colorpicker.html