here2share

# Tk_img_transparency.py

Aug 20th, 2015
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. # Tk_img_transparency.py
  2.  
  3. from Tkinter import Tk, Frame, Canvas
  4. from PIL import Image,ImageTk
  5. import urllib2
  6. import sys
  7. import base64
  8.  
  9. t = Tk()
  10. t.title("Transparency")
  11.  
  12. frame = Frame(t)
  13. frame.pack()
  14.  
  15. canvas = Canvas(frame, bg="gray", width=400, height=400)
  16. canvas.pack()
  17.  
  18. try:
  19.     photoimage1 = ImageTk.PhotoImage(file="solidball.png")
  20.     photoimage2 = ImageTk.PhotoImage(file="example.png")
  21. except:
  22.     def oURL(dd):
  23.         URL = 'http://tinyurl.com/h2sball00'+str(dd)
  24.  
  25.         u = urllib2.urlopen(URL)
  26.         raw_data = u.read()
  27.         u.close()
  28.         b64_data = base64.encodestring(raw_data)
  29.         return PhotoImage(data=b64_data)
  30.     photoimage1 = oURL(1)
  31.     photoimage2 = oURL(2)
  32.     photoimage1.save()
  33.     photoimage2.save()
  34. #
  35. canvas.create_image(150, 150, image=photoimage1)
  36. canvas.create_image(250, 250, image=photoimage2)
  37.  
  38. t.mainloop()
Add Comment
Please, Sign In to add comment