2017-04-16 3 views
0

팝업에서 ColorPicker에 q 문제가 있습니다. 'PICK AND CLOSE'키를 누른 후 색상 값 (#없이 16 진 코드)이 필요하지만 두번만 흰색 값이 인쇄됩니다. 실행 코드 후 Kivy가 ColorPicker에서 색상 값을 반환하지 않습니다.

내 코드 (파이썬 3.6, kivy 1.9.1은) :

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

Builder.load_string(''' 
<PaintWindow>: 
    orientation: 'vertical' 

<PopupColor>: 
    title: 'Pick a Color' 
    size_hint: 1.0, 0.6 
    id: popupcolor 

    BoxLayout: 
     orientation: 'vertical' 

     ColorPicker: 
      size_hint: 1.0, 1.0 

     Button: 
      text: 'PICK AND CLOSE' 
      color: 0.435, 0.725, 0.56, 1 
      background_color: 0, 0.26, 0.27, 1 
      size_hint: 1.0, 0.2 
      on_press: popupcolor.on_press_dismiss() 
''') 


class PaintWindow(BoxLayout): 
    pass 


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


class PopupRun(App): 
    def build(self): 
     main_window = PaintWindow() 
     popup = PopupColor() 
     popup_color = ColorPicker() 
     popup.open() 

     def on_color(instance, value): 
      print("RGBA = ", str(value)) 
      print("HSV = ", str(instance.hsv)) 
      print("HEX = ", str(instance.hex_color)) 
      hex_color = str(instance.hex_color) 
      # Return hex color code without '#' 
      return hex_color[1:] 

     # Return valye after change color in ColorPicker 
     popup_color.bind(color=on_color) 

     return main_window 


PopupRun().run() 

답변

0

당신은 해고 방법에 ColorPicker를 전달할 수 있습니다.
먼저 당신의 ColorPicker에게 KV의 ID 제공 :

ColorPicker: 
    id: colorpicker 
    size_hint: 1.0, 1.0 
다음

on_press 방법에 전달 :

Button: 
    text: 'PICK AND CLOSE' 
    color: 0.435, 0.725, 0.56, 1 
    background_color: 0, 0.26, 0.27, 1 
    size_hint: 1.0, 0.2 
    on_press: popupcolor.on_press_dismiss(colorpicker) 

그리고 파이썬 :

class PopupColor(Popup): 
    def on_press_dismiss(self, colorpicker, *args): 
     self.dismiss() 
     color = str(colorpicker.hex_color)[1:] 
     print(color) 
관련 문제