Advertisement
here2share

# Tk_opacity.py

Nov 26th, 2019
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.18 KB | None | 0 0
  1. # Tk_opacity.py
  2.  
  3. # explore Tkinter opacity
  4. # show image without root title or root border
  5. # you have to add a way to exit, like mouse double click
  6. try:
  7.     # Python2
  8.     from Tkinter import *
  9. except ImportError:
  10.     # Python3
  11.     from tkinter import *
  12. def exit(event=None):
  13.     root.destroy()
  14. root = Tk()
  15.  
  16. import base64
  17. import os
  18. from cStringIO import StringIO
  19. from PIL import ImageTk, Image
  20.  
  21. py_gif_b64='''\
  22. R0lGODlhQABAAPcAAAAAAAAPMwAXNwAaOAAYQwAbQQAdQQAbTwAeSwAWUQMmQgAjSwEnSwYuTwoo
  23. SggtSAwrSAAlVAAgWQAmWAAqVgAuVwAuXQcuWAw1TQs5Xhk0SQAsYwAxZAA1YQA0bAA6bAA/dyw/
  24. UAxAbgxGeh5BYRxHbRRKdBRNfi5IXC5OaCJQdCNUfzdTajlQYj1UaTJWdDZge0BXaUZZaE1dakJa
  25. cEBffElhc0lieUlmfU9leQZJgBRVjB5bjypehzNXhzFbgTlchiZjljhkhzRplixtozNwozF1qzp4
  26. q0BehERmhENli0dshUZvjktylk1wkE92kltvgVBwiVp1g1lyiVl1il95j1B3l1V3klh6lmB2iWt7
  27. lUWDuUaIvEqCskmGul6Col2FqVSLtVONvVqMtl+NsWaInmmAlGyGnHOGlHGHmXGKnnqJk3mMm3uR
  28. lX2Qn2SGpmqIoW+Pp2yOrGeRuXGLoneOoHaPo3STp3eSrXyRonWZuX2gvmOWwW2aw2meynOfwnGh
  29. yXuhw3yly3iqz3ypz3Sl0HCp1pt+Ha6ED6SAE6yDGqeRF7OEBbqTCriTFr6fEKyJLaODMKWWJqWS
  30. M7WTI7aWN62iJrqlKrekOJiOR5uRTKSTRqaXVa2bV7mZR7mdVKmeZ62da62ec7Cfd7ujRrCmXrGt
  31. W7yoWq6jaqyicbWga7OpbbqpbbSrebmueMGXC8SaFcSZJcOcNcqjGtSoHc2pJ8yrOcG1P9iuKdG4
  32. LdC5PtmwPNq5MN29PcurScqtWtG8S9uwS9G8X921Xsmvbc2yd9C9cN/AUNHAfeHKRePMUuDDYOTP
  33. ZODFcubPdOLIfoKPmIGZq4qcrIGasYedsYOgs4eiv5euvoSjwIapx4KozYSrzI6wzoaw1Iux1Y+1
  34. 1oq12JSyz5K00Ji305i72qC706C92Z3B3JnA4aTC26vF3KXI5K/Q6s/CjtTOgdvGjtLHmtPNltTP
  35. odTQreXRgunXk+nZp+/ki+zimu/lqQAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAP8ALAAAAABAAEAA
  36. AAj/AP8JHEiwoEGB16qdiVMmzh1p1KhNi1bnzBk809Ic3MixI0czNKhUK5du3bl06cqpVGlOnTpz
  37. 5M60cOOxps2BaSDI+faNGzdx38B92zYunE+f4cQdNTdFg52bUA+mMTCHULdAe7JtA1SIkCBtgsIS
  38. 8hookLay274I0Bi17b8GFgqN+XFmWpQvgPj48ZNXr19Affj0yetHhQK3UeEs+CBGBbSBV4SImSyG
  39. Dx/KYsLwGZN5cpcAZhDflENgAgG2AxEE2SJmi+stXMQc6UK7y5HbRwgcFl3zzYTfjwl2kLCDyBYj
  40. Ro4kx32EyG0iQwoEyMPbo5XfE1ALnODBwwcdO8IH/9kRpHx5HkF6iCAQAEP1jlh+W4AR/N+ZCRs+
  41. 6Peuvz//Dx2Yxp577230hQUfnCACGNhY84YIGXwgggggiKBfB/oh6MEEFkRAwIcCEFigQW+ssEIQ
  42. K4jgww8liGDiixNeiOAH+VGwwAIftjfiQXGUMEQRQwzxYnpDCCFkihd+YAEHHFhgwQQIgCjijgPF
  43. QcILLwjxgwo9/PCCl1i+oIIJImA4o5MdQklAiFQWBA0ba8S5RhppoNEGGmiwkQYdU2DIJJpoYkfA
  44. AFO2CVUaC8gHYAdocvDboIW6NcUUL6DQggssXMrCppyG6SmWKpSG4AQdMFoBBRQ8GcEC7qWCCies
  45. o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4OIYwv82
  72. GcDeETB71OMdHwf5KTp95BQH8ORRUzOik31sYrNi4AsvuOkMPDpR/tGEo9OFL37BilOseRifALqh
  73. cq0L9J6Xeib841OXgW9S2GIXwYiE1Ns08zQnd7m9iOIVZxHXaJ/CE3SGRNVkDoxfH/e0x0ita/2G
  74. C1jQIhbNKAgx6FyJsVPpFOQ8bamdFucX2wIXdKZHQX5BiVh4Qt2GIoYwmHYyw6LMGTnfhQkp4Yto
  75. t6ISlJAF5qduDGYYw/NmPXbObWGLWlTiGac4xSpIkXpPgLwgyNhWsY9tbGKjNee6oH0lfvELT1Ri
  76. +auX+SmUzfNkN+PYwzgG7Xchi+57ghjR/70rCKfPc24pO87L8MUwfLH08It/ILkPqjEaTf9hFBX8
  77. 7n9/QXLP//73f0cBAQA7
  78. '''
  79.  
  80. f = StringIO(base64.decodestring(str(py_gif_b64)))
  81. image = Image.open(f)
  82.  
  83.  
  84. root.title("Tk_opacity")
  85. # only set x, y position of root
  86. x = 400
  87. y = 400
  88. root.geometry("+%d+%d" % (x, y))
  89. tkpi = ImageTk.PhotoImage(image)
  90.  
  91. # use opacity alpha values from 0.0 to 1.0
  92. # lower alpha is most transparent
  93. # opacity/transparency applies to image too
  94. root.wm_attributes('-alpha', 0.7)  
  95. # remove border from root window
  96. root.overrideredirect(1)
  97.  
  98. Label(root, image=tkpi).pack()
  99. # double click mouse on picture to exit
  100. root.bind('<Double-1>', exit)
  101. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement