Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_basic_paint_demo2.py
- from Tkinter import *
- root = Tk()
- root.geometry("500x500")
- h = Scrollbar(root, orient=HORIZONTAL)
- v = Scrollbar(root, orient=VERTICAL)
- canvas = Canvas(root, scrollregion=(0, 0, 1000, 1000), yscrollcommand=v.set, xscrollcommand=h.set)
- h['command'] = canvas.xview
- v['command'] = canvas.yview
- canvas.grid(column=0, row=0, sticky=(N,W,E,S))
- h.grid(column=0, row=1, sticky=(W,E))
- v.grid(column=1, row=0, sticky=(N,S))
- root.grid_columnconfigure(0, weight=1)
- root.grid_rowconfigure(0, weight=1)
- lastx, lasty = 0, 0
- import PIL.ImageGrab
- def xy(event):
- global lastx, lasty, xyColor
- lastx, lasty = canvas.canvasx(event.x), canvas.canvasy(event.y)
- rgb = PIL.ImageGrab.grab().load()[event.x, event.y]
- print "Clicked at: ", event.x, event.y
- if event.x > 10 and event.x < 30 and event.y > 10 and event.y < 30+y:
- #xyColor = '#%02x%02x%02x' % rgb ### ???
- print colors[(event.y-10)/25]
- xyColor = colors[(event.y-10)/25]
- pass
- def addLine(event):
- global lastx, lasty
- x, y = canvas.canvasx(event.x), canvas.canvasy(event.y)
- if event.x > 40:
- canvas.create_line((lastx, lasty, x, y), fill=xyColor, width=5, tags='currentline')
- lastx, lasty = x, y
- else: lastx, lasty = 40, y
- def doneStroke(event):
- canvas.itemconfigure('currentline', width=1)
- canvas.bind("<Button-1>", xy)
- canvas.bind("<B1-Motion>", addLine)
- canvas.bind("<B1-ButtonRelease>", doneStroke)
- colors = 'red orange yellow green blue purple pink brown white grey black'.split()
- y=0
- for c in colors:
- id = canvas.create_rectangle((10, 10+y, 30, 30+y), fill=c)
- y+=25
- xyColor='red'
- canvas.itemconfigure('palette', width=5)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement