Paint on Tkinter Canvas
Paint on Canvas .
Welcome back to an another Tkinter article in this article we are creating a simple paint using tkinter python.
.
So lets code .
       			 
# Tkinter Tutorial : Dynamic Coding
# canvas Widget .....
# draw on Canvas .....
#Simple Paint App
# Import library
from tkinter import *  
root = Tk()   
# Create Title 
root.title(  " Dynamic Coding - Paint App ") 
  
# specify size 
root.geometry("500x350") 
  
# define function when   
# mouse double click is enabled 
def display( event ): 
     
    # Co-ordinates. 
    x1, y1, = ( event.x - 3 ),( event.y - 3 ),
    x2, y2 = ( event.x + 3 ),( event.y + 3 )  
      
    # Colour 
    color = 'black'
      
    # specify type of display 
    w.create_oval( x1, y1, x2,  
                  y2, fill = color,outline=color ) 
  
  
# create canvas widget. 
w = Canvas(root, width = 500, height = 350,bg='white')  
  
# call function when double  
# click is enabled. 
w.bind( "<B1-Motion>",display ) 
w.pack() 
  
root.mainloop() 
 Output .
So how the code is working .
basically we bind the mouse drag to a function named display which creates a oval on the place where the mouse drag event occur .
Traceback (most recent call last):
ReplyDeleteFile "c:\Users\Arun\Desktop\PyFiles\main.py", line 39, in
w.bind( "",display )
File "C:\Python 3.7\lib\tkinter\__init__.py", line 1251, in bind
return self._bind(('bind', self._w), sequence, func, add)
File "C:\Python 3.7\lib\tkinter\__init__.py", line 1206, in _bind
self.tk.call(what + (sequence, cmd))
_tkinter.TclError: bad event type or keysym "b1"
#ERROR are coming while running it can u give me any solution of this.
sorry for syntax mistake , now the code is updated you can check it out and thanks for your comment .
Deletekeep learning and coding @dynamiccoding