Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparent background in a Tkinter window

Is there a way to create a "Loading Screen" in Python 3.x using Tkinter? I mean like the loading screen for Adobe Photoshop, with transparency and so on. I managed to get rid of the frame border already using:

root.overrideredirect(1)

But if I do this:

root.image = PhotoImage(file=pyloc+'\startup.gif')
label = Label(image=root.image)
label.pack()

the image displays fine, but with the grey window background instead of transparency.

Is there a way of adding transparency to a window, but still displaying the image correctly?

like image 592
forumfresser Avatar asked Sep 29 '13 16:09

forumfresser


1 Answers

It is possible, but it's OS-dependent. This will work in Windows:

import Tkinter as tk # Python 2
import tkinter as tk # Python 3
root = tk.Tk()
# The image must be stored to Tk or it will be garbage collected.
root.image = tk.PhotoImage(file='startup.gif')
label = tk.Label(root, image=root.image, bg='white')
root.overrideredirect(True)
root.geometry("+250+250")
root.lift()
root.wm_attributes("-topmost", True)
root.wm_attributes("-disabled", True)
root.wm_attributes("-transparentcolor", "white")
label.pack()
label.mainloop()
like image 106
dln385 Avatar answered Oct 04 '22 06:10

dln385