Advertisement
GERMANYDOV

Risovalka

Feb 21st, 2020
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. from tkinter import *
  2. from tkinter import colorchooser
  3.  
  4. root = Tk()
  5.  
  6. def btn_click(event):
  7. global color
  8. t = event.widget
  9. color = t['bg']
  10.  
  11. colors = ['red', 'orange', 'yellow', 'green', 'cyan', 'blue', 'purple']
  12. for i in range(7):#i = 0, 1, 2, 3, 4, 5, 6
  13. btn = Button(width = 10, bg = colors[i])
  14. btn.grid(row = 0, column = i)
  15. btn.bind('<Button-1>', btn_click)
  16.  
  17. c = Canvas(width = 500, height = 500, bg = 'white')
  18. c.grid(row = 1, column = 0, columnspan = 7)
  19.  
  20. lastX = lastY = 0
  21. t = 3
  22. color = 'black'
  23.  
  24. def save_position(event):
  25. global lastX, lastY
  26. lastX = event.x
  27. lastY = event.y
  28.  
  29. def on_click(event):
  30. save_position(event)
  31.  
  32. def on_drag(event):
  33. c.create_line(lastX,lastY,event.x, event.y, fill = color, width = t)
  34. save_position(event)
  35.  
  36. c.bind('<Button-1>', on_click)
  37. c.bind('<B1-Motion>', on_drag)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement