Advertisement
gorskaja2019

Untitled

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