2017-04-19 75 views
1

如何更改我製作的kivy Paint應用程序中的線條顏色。我可以改變線條的寬度,但是我找不到改變線條顏色的任何東西。KIVY:更改Paint App中的線條顏色

我的代碼:

from kivy.app import App 
from kivy.uix.widget import Widget 
from kivy.graphics import Line 
class DrawRandom(Widget): 
    def on_touch_down(self, touch): 
     with self.canvas: 
      touch.ud["line"]=Line(points=(touch.x,touch.y),width=5) 
    def on_touch_move(self, touch): 
     touch.ud["line"].points += (touch.x, touch.y) 

class PaintApp(App): 
    def build(self): 
     return DrawRandom() 


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

回答

2

只需添加顏色到你的畫布。
在您的導入導入顏色。

from kivy.graphics import Line, Color 

然後在您的Painter類中爲畫布添加顏色。在這個例子中,我嘗試了紅色。
它的rgba值。

def on_touch_down(self, touch): 
    with self.canvas: 
     Color(1,0,0,1) 
     touch.ud["line"] = Line(points = (touch.x, touch.y)) 
+0

非常感謝!我錯過了導入Color。那讓生活變得很悲慘。 – thechargedneutron

+0

@thechargedneutron你很好:) – EL3PHANTEN