Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_fade_out_image.py -- ZZZ unable figure this one out at the moment
- from Tkinter import *
- from PIL import Image,ImageTk,ImageDraw
- import urllib2
- import sys
- import base64
- t = Tk()
- t.title("Fade Out Image")
- frame = Frame(t)
- frame.pack()
- canvas = Canvas(frame, bg="gray", width=400, height=400)
- canvas.pack()
- def fade():
- global img
- canvas.delete('all')
- create1()
- if img.image_alpha < 255:
- #img.set_alpha(img.image_alpha)
- canvas.create_image(150, 150, image=img)
- print (img.image_alpha)
- img.image_alpha += int(255/img.fade_frame_number)
- t.after(img.milsec/img.fade_frame_number, fade)
- else: btn.configure(state=NORMAL); img=''
- create2()
- #
- img=''
- def fade_out():
- global img
- btn.configure(state=DISABLED)
- img=image1
- img.image_alpha = 0
- img.fade_frame_number = 30
- img.milsec = 3000 # 3 second fade
- fade()
- #
- solidball = "solidball.png"
- example = "example.png"
- try:
- image1 = ImageTk.PhotoImage(file=solidball)
- image2 = ImageTk.PhotoImage(file=example)
- print 'Images copied from URL to drive'
- except:
- def oURL(dd):
- URL = 'http://tinyurl.com/h2sball00'+str(dd)
- u = urllib2.urlopen(URL)
- raw_data = u.read()
- u.close()
- b64_data = base64.encodestring(raw_data)
- return PhotoImage(data=b64_data)
- image1 = oURL(1)
- image2 = oURL(2)
- image1.save()
- image2.save()
- #
- def create1():
- canvas.create_rectangle((100, 100, 300, 300), fill="darkgray")
- def create2():
- canvas.create_image(250, 250, image=image2)
- create1()
- canvas.create_image(150, 150, image=image1)
- create2()
- btn = Button(t, text=" Click To Fade Away An Image... ", command=fade_out)
- btn.pack()
- t.mainloop()
- photo1 = Image.open(solidball)
- photo2 = Image.open(example)
- base, overlay = photo1, photo2
- bands = list(overlay.split())
- if len(bands) == 4:
- # Assuming alpha is the last band
- bands[3] = bands[3].point(lambda x: x*0.5)
- overlay = Image.merge(overlay.mode, bands)
- base.paste(overlay, (0, 0), overlay)
- base.show()
Add Comment
Please, Sign In to add comment