Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- from tkinter import colorchooser
- root = Tk()
- def btn_click(event):
- global color
- t = event.widget
- color = t['bg']
- colors = ['red', 'orange', 'yellow', 'green', 'cyan', 'blue', 'purple']
- for i in range(7):#i = 0, 1, 2, 3, 4, 5, 6
- btn = Button(width = 10, bg = colors[i])
- btn.grid(row = 0, column = i)
- btn.bind('<Button-1>', btn_click)
- c = Canvas(width = 500, height = 500, bg = 'white')
- c.grid(row = 1, column = 0, columnspan = 7)
- lastX = lastY = 0
- t = 3
- color = 'black'
- def save_position(event):
- global lastX, lastY
- lastX = event.x
- lastY = event.y
- def on_click(event):
- save_position(event)
- def on_drag(event):
- c.create_line(lastX,lastY,event.x, event.y, fill = color, width = t)
- save_position(event)
- c.bind('<Button-1>', on_click)
- c.bind('<B1-Motion>', on_drag)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement