Advertisement
here2share

# Tk_basic_paint_demo.py

May 12th, 2021
1,127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. # Tk_basic_paint_demo.py
  2.  
  3. from Tkinter import *
  4.  
  5. canvas_width=500
  6. canvas_height=400
  7. px=py=None
  8.  
  9. def oRGB(rgb): # pass
  10.     r,g,b = rgb
  11.     return "#%02x%02x%02x" % (r,g,b)
  12.  
  13. def paint(event):
  14.     global px,py
  15.     x,y=event.x, event.y
  16.     w.create_line((x, y, px, py), width=3, fill=oRGB([255,128,0]))
  17.     px,py=x,y
  18.  
  19. def mouse_btn_down(event):
  20.     global px,py
  21.     px,py=event.x, event.y
  22.  
  23. master=Tk()
  24. master.title("Tk Basic Paint Demo")
  25. w = Canvas(master,
  26.            width=canvas_width,
  27.            height=canvas_height)
  28. w.pack(expand=YES, fill=BOTH)
  29. w.bind("<B1-Motion>", paint)
  30. w.bind('<1>', mouse_btn_down)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement