from tkinter import *
from tkinter import ttk

lastx, lasty = 0, 0
color = 'black'

def setColor(newcolor):
    global color
    color = newcolor
    canvas.dtag('all', 'paletteSelected')
    canvas.itemconfigure('palette', outline = 'white')
    canvas.addtag('paletteSelected', 'withtag', 'palette%s' % color)
    canvas.itemconfigure('paletteSelected', outline = '#999999')

def xy(event):
    global lastx, lasty
    lastx, lasty = event.x, event.y

def addLine(event):
    global lastx, lasty
    canvas.create_line(lastx, lasty, event.x, event.y, fill = color, width = 3, tags = 'currentline')
    lastx, lasty = event.x, event.y

def doneStroke(event):
    canvas.itemconfigure('currentline', width = 1)

root = Tk()
root.columnconfigure(0, weight = 1)
root.rowconfigure(0, weight = 1)

canvas = Canvas(root)
canvas.grid(column = 0, row = 0, sticky = (N, W, E, S))
canvas.bind('<Button-1>', xy)
canvas.bind('<B1-Motion>', addLine)
canvas.bind('<B1-ButtonRelease>', doneStroke)

id = canvas.create_rectangle((10, 10, 30, 30), fill="red", tags=('palette', 'palettered'))
canvas.tag_bind(id, '<Button-1>', lambda x: setColor('red'))
id = canvas.create_rectangle((10, 35, 30, 55), fill="blue", tags=('palette', 'paletteblue'))
canvas.tag_bind(id, '<Button-1>', lambda x: setColor('blue'))
id = canvas.create_rectangle((10, 60, 30, 80), fill="black", tags=('palette', 'paletteblack', 'paletteSelected'))
canvas.tag_bind(id, '<Button-1>', lambda x: setColor('black'))

setColor('black')
canvas.itemconfigure('palette', width=1)

root.mainloop()
from tkinter import *
from tkinter import ttk

lastx, lasty = 0, 0
color = 'black'

def setColor(newcolor):
    global color
    color = newcolor
    canvas.dtag('all', 'paletteSelected')
    canvas.itemconfigure('palette', outline = 'white')
    canvas.addtag('paletteSelected', 'withtag', 'palette%s' % color)
    canvas.itemconfigure('paletteSelected', outline = '#999999')

def xy(event):
    global lastx, lasty
    lastx, lasty = event.x, event.y

def addLine(event):
    global lastx, lasty
    canvas.create_line(lastx, lasty, event.x, event.y, fill = color, width = 3, tags = 'currentline')
    lastx, lasty = event.x, event.y

def doneStroke(event):
    canvas.itemconfigure('currentline', width = 1)

root = Tk()
root.columnconfigure(0, weight = 1)
root.rowconfigure(0, weight = 1)

canvas = Canvas(root)
canvas.grid(column = 0, row = 0, sticky = (N, W, E, S))
canvas.bind('<Button-1>', xy)
canvas.bind('<B1-Motion>', addLine)
canvas.bind('<B1-ButtonRelease>', doneStroke)

id = canvas.create_rectangle((10, 10, 30, 30), fill="red", tags=('palette', 'palettered'))
canvas.tag_bind(id, '<Button-1>', lambda x: setColor('red'))
id = canvas.create_rectangle((10, 35, 30, 55), fill="blue", tags=('palette', 'paletteblue'))
canvas.tag_bind(id, '<Button-1>', lambda x: setColor('blue'))
id = canvas.create_rectangle((10, 60, 30, 80), fill="black", tags=('palette', 'paletteblack', 'paletteSelected'))
canvas.tag_bind(id, '<Button-1>', lambda x: setColor('black'))

setColor('black')
canvas.itemconfigure('palette', width=1)

root.mainloop()