Advertisement
here2share

# semi-transparent-stipple-demo.py

May 21st, 2018
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.43 KB | None | 0 0
  1. # semi-transparent-stipple-demo.py
  2.  
  3. # note: stipple only works for some objects (like rectangles)
  4. # and not others (like ovals).  But it's better than nothing...
  5.  
  6. from Tkinter import *
  7.  
  8. def redrawAll(canvas):
  9.     canvas.delete(ALL)
  10.     # draw a red rectangle on the left half
  11.     canvas.create_rectangle(0, 0, 250, 600, fill="red")
  12.     # draw semi-transparent rectangles in the middle
  13.     canvas.create_rectangle(200,  75, 300, 125, fill="blue", stipple="")
  14.     canvas.create_rectangle(200, 175, 300, 225, fill="blue", stipple="gray75")
  15.     canvas.create_rectangle(200, 275, 300, 325, fill="blue", stipple="gray50")
  16.     canvas.create_rectangle(200, 375, 300, 425, fill="blue", stipple="gray25")
  17.     canvas.create_rectangle(200, 475, 300, 525, fill="blue", stipple="gray12")
  18.  
  19. def init(canvas):
  20.     redrawAll(canvas)
  21.  
  22. ########### copy-paste below here ###########
  23.  
  24. def run():
  25.     # create the root and the canvas
  26.     root = Tk()
  27.     canvas = Canvas(root, width=500, height=600)
  28.     canvas.pack()
  29.     # Store canvas in root and in canvas itself for callbacks
  30.     root.canvas = canvas.canvas = canvas
  31.     # Set up canvas data and call init
  32.     canvas.data = { }
  33.     init(canvas)
  34.     # set up events
  35.     # root.bind("<Button-1>", mousePressed)
  36.     # root.bind("<Key>", keyPressed)
  37.     # timerFired(canvas)
  38.     # and launch the app
  39.     root.mainloop()  # This call BLOCKS (so your program waits until you close the window!)
  40.  
  41. run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement