Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_img_opacity_trick.py -- has a few minor drawbacks
- from Tkinter import *
- from cStringIO import StringIO
- from PIL import ImageTk, Image
- import base64, zlib
- root = Tk()
- ws = root.winfo_screenwidth() # width of the screen
- hs = root.winfo_screenheight() # height of the screen
- ww = 300
- hh = 300
- # calculate x and y coordinates for the Tk root window
- xx = (ws/2) - (ww/2)
- yy = (hs/2) - (hh/2)
- root.geometry("%dx%d%+d%+d" % (ww, hh, xx, yy))
- b64='''\
- eJztWPdTE86+TUICCaEE6T0QWui9S0IHpYMU6UgXDU2aUhKKFJHQi1QBqUJEpINUqUpVlCJViiKg
- WBCBXL533nv/wv3hvjPzmT17dmZ3Zmc/O5/zSTIz0ael5qAGAAC0hgY6FgAAEPtPQCkulBOTa3kX
- AzDIQl8L0PCGa/diAvbSNNYEAJ6lwU9dIQAABcDMyEr3QidQUcVCoXHU1PE0NAl0dElMTMksLMms
- rClsbCns7A84OB5wcqZycaVycz/k4UlDItP4+Ij8/EQUKl1AIF1QMENIKENYOFNEJBONzhIVzRIT
- yxYXz5aQyJGUzJGSypWWzpOVzZOTy5eXz1dQKFBULFBSeqSs/EhFpVBVtUhdvVhDoxiDKcFiSzQ1
- S7W0SrW1y3R0ynR1H+vplRsYlBsaVly5UnH1aqWRUaWx8RMTkyemplVmZtUWFtWWljVWVjXXrtVa
- W9fa2NTZ2tbZ2dXb2z91cHjq6Njg5NTg7Nzo4tLo6kpyc3vm4dHk6dnk5fXc2/u5j0+zr28LDtca
- ENAWGNgREtIRGtoZHt4dGdkTFQX4f/w34ToWvX6RJ4BgCxNL8n83AJa/qQQvrgTmb2AXBADQDfwT
- wGFctfuFyB6saxtsifMMDnUN9AD4u/rcDpa87RGMlJeUlpSV+Yb0yQYAGFoMdTStwpy+FqXaLw2y
- 3Med1b+tKzVIT7uZDhF31Lg6fQXd1OkCXGy65YO/OK96dL9RPvOyV0a+XCb4ILxkeNscmR/kJJw/
- KUA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41W42wLJNF2kCXP4bJBhTor
- zpLHXU+smyqW127b0JASqCPYgl3syT8GL5DdUD29v4dbPnVU+w03RMGYoUZYLebY/g2L1F5Vpser
- 760ESYHxIgqqb2H1c8jk+hhqyO1cnkWY4dXaB9QQ67c8NtO/oi5MNWya2dr2D+WFzwbm6wF1rQxo
- QRvowV2xShY8ekSFTfnWpznBwzC1nWX/zoUclPYtBWngKBVAuD5WFSKEjYEW1gr5sigXNsbCvPzD
- ns5JSrtOm66t9i74EHqDIVKVza/c63MQuMrX8Z5QLtkpW5eA1Qb2zwnyhqWwB8BTUri8zSqt5n+2
- rfE/NDmMfM4rS4apTQu6cv7TDzPUNdFp0HIh/AtH+5Nu'''
- b64 = base64.decodestring(b64)
- zzz = StringIO(zlib.decompress(b64))
- img_data = Image.open(zzz)
- img = ImageTk.PhotoImage(img_data)
- cv = Canvas(root, width=300, height=300)
- cv.grid(row=0, column=0)
- cv.create_rectangle(0, 0, 180, 180, fill='blue')
- cv.create_rectangle(120, 120, 300, 300, fill='yellow')
- top = Toplevel()
- top.geometry("%dx%d%+d%+d" % (ww, hh, xx+8, yy+32))
- top2 = Toplevel()
- top2.geometry("%dx%d%+d%+d" % (ww, hh, xx+8, yy+32))
- cv2 = Canvas(top, width=300, height=300, bg='white')
- cv2.grid(row=0, column=0)
- cv2.master.overrideredirect(True)
- cv2.master.wm_attributes("-topmost", True)
- cv2.master.wm_attributes('-transparentcolor', 'white')
- cv2.master.wm_attributes('-alpha', 0.85)
- cv2.create_image(150, 150, image=img)
- cv3 = Canvas(top2, width=300, height=300, bg='darkgreen')
- cv3.grid(row=0, column=0)
- cv3.master.overrideredirect(True)
- cv3.master.wm_attributes("-topmost", True)
- cv3.master.wm_attributes('-transparentcolor', 'darkgreen')
- cv3.create_text(150, 150, text='TKINTER', font=('', 32, 'bold', 'italic'), fill='green')
- top.lift() #???
- def configure(event):
- xx, yy = event.x, event.y
- if xx and yy:
- top.geometry("%dx%d%+d%+d" % (ww, hh, xx+8, yy+32))
- top2.geometry("%dx%d%+d%+d" % (ww, hh, xx+8, yy+32))
- root.bind("<Configure>", configure)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement