Drawing App For Kivy

 Below here is the source code for Drawing Application for kivy. Please if you like this content. Don't forget to Subscribe to my YouTube Channel here now on Python Programming now or other programming content now and please support me on PayPal Now for better content! and Join our WhatsApp group here or here also with our Telegram group here to start learning now! Thanks!



from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.graphics import Color, Line
from kivy.core.window import Window

class DrawingApp(App):
def build(self):
self.drawing_widget = DrawingWidget()
self.erase_button = Button(text="Erase", size_hint=(None,None), size=(100,50), pos=(0,Window.height - 50))
self.erase_button.bind(on_press=self.toggle_color)
self.root = Widget()
self.root.add_widget(self.drawing_widget)
self.root.add_widget(self.erase_button)
return self.root

def toggle_color(self, instance):
self.drawing_widget.toggle_color()
self.update_button_style()

def update_button_style(self):
if self.drawing_widget.color == (1,0,0):
self.erase_button.background_color = (0.6,0.6,0.6,1)
else:
self.erase_button.background_color = (0,0,1,1)




class DrawingWidget(Widget):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.color = (1,0,0)
self.line_width = 2


def on_touch_down(self, touch):
with self.canvas:
Color(*self.color)
touch.ud['line'] = Line(points=(touch.x, touch.y), width=self.line_width)


def on_touch_move(self,touch):
touch.ud['line'].points += (touch.x,touch.y)



def toggle_color(self):
if self.color == (1,0,0):
self.color = (0,0,0)
self.line_width = 5

else:
self.color = (1,0,0)
self.line_width = 2



if __name__ == '__main__':
DrawingApp().run()


No comments:

Post a Comment

Drawing App For Kivy

  Below here is the source code for Drawing Application for kivy. Please if you like this content.  Don't forget to Subscribe to my YouT...