如何更改我制作的 kivy Paint 应用程序中的线条颜色。我可以更改线条宽度,但找不到任何可以更改线条颜色的内容。
我的代码:
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()
最佳答案
您只需将颜色添加到 Canvas 即可。
在您的导入中也导入颜色。
from kivy.graphics import Line, Color
并在您的 Painter 类中将颜色添加到 Canvas 。在这个例子中我尝试红色。
它的 rgba 值。
def on_touch_down(self, touch):
with self.canvas:
Color(1,0,0,1)
touch.ud["line"] = Line( points = (touch.x, touch.y))
关于python - KIVY:在 Paint App 中更改线条颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43501386/