Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- from tkinter import colorchooser
- from random import *
- root = Tk()
- #очистка
- def clear_on_click(event):
- c.delete('all')
- btn_clear = Button(width = 10, text = 'Clear', bg = 'lightgreen')
- btn_clear.grid(row = 1, column = 6)
- btn_clear.bind('<Button-1>', clear_on_click)
- def btn_click(event):
- global color
- t = event.widget
- color = t['bg']
- def rbtn_click(event):
- global color
- r = "%02x"%randint(0,255)
- g = "%02x"%randint(0,255)
- b = "%02x"%randint(0,255)
- color = '#'+r+g+b
- #рандомный цвет
- btn_random = Button(width = 10, text = 'Рандом', bg = 'darkblue')
- btn_random.grid(row = 0, column = 7)
- btn_random.bind('<Button-1>', rbtn_click)
- 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 = 600, height = 500, bg = 'white', cursor = 'pencil')
- c.grid(row = 2, 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