Advertisement
gorskaja2019

Untitled

Apr 10th, 2019
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. from tkinter import *
  2. from tkinter import colorchooser
  3. from random import *
  4.  
  5. root = Tk()
  6. #очистка
  7. def clear_on_click(event):
  8. c.delete('all')
  9.  
  10. btn_clear = Button(width = 10, text = 'Clear', bg = 'lightgreen')
  11. btn_clear.grid(row = 1, column = 6)
  12. btn_clear.bind('<Button-1>', clear_on_click)
  13.  
  14. def btn_click(event):
  15. global color
  16. t = event.widget
  17. color = t['bg']
  18.  
  19. def rbtn_click(event):
  20. global color
  21. r = "%02x"%randint(0,255)
  22. g = "%02x"%randint(0,255)
  23. b = "%02x"%randint(0,255)
  24. color = '#'+r+g+b
  25.  
  26. #рандомный цвет
  27.  
  28. btn_random = Button(width = 10, text = 'Рандом', bg = 'darkblue')
  29. btn_random.grid(row = 0, column = 7)
  30. btn_random.bind('<Button-1>', rbtn_click)
  31.  
  32.  
  33.  
  34.  
  35. colors = ['red', 'orange', 'yellow', 'green', 'cyan', 'blue', 'purple']
  36. for i in range(7):#i = 0, 1, 2, 3, 4, 5, 6
  37. btn = Button(width = 10, bg = colors[i])
  38. btn.grid(row = 0, column = i)
  39. btn.bind('<Button-1>', btn_click)
  40.  
  41. c = Canvas(width = 600, height = 500, bg = 'white', cursor = 'pencil')
  42. c.grid(row = 2, column = 0, columnspan = 7)
  43.  
  44. lastX = lastY = 0
  45. t = 3
  46. color = 'black'
  47.  
  48. def save_position(event):
  49. global lastX, lastY
  50. lastX = event.x
  51. lastY = event.y
  52.  
  53. def on_click(event):
  54. save_position(event)
  55.  
  56. def on_drag(event):
  57. c.create_line(lastX,lastY,event.x, event.y, fill = color, width = t)
  58. save_position(event)
  59.  
  60. c.bind('<Button-1>', on_click)
  61. c.bind('<B1-Motion>', on_drag)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement