Reputation: 1
Having trouble displaying image (PIL/tkinter). Image displays but with transparent background.
import tkinter as tk
from PIL import Image, ImageTk
path = "zzz.png"
root = tk.Tk()
img = ImageTk.PhotoImage(Image.open(path))
panel = tk.Label(root, image = img)
panel.pack(side = "bottom", fill = "both", expand = "yes")
root.mainloop()
I want background to be opaque.
I noticed that this is only an issue in a gnome3 desktop; where the program launches from a gnome-terminal.
Another update. Only issue when running desktop remotely using xrdp. Following link shows similar issue:
https://github.com/neutrinolabs/xrdp/issues/1906 However; I am not able to get xrdb working in 24bit color depth mode.
screenshot of program's output displayed on an xrdp desktop. image that may be used in program.
Upvotes: 0
Views: 90
Reputation: 4560
How to Display tkinter image without transparent background
Try this without using PIL namespace.
wm_attributes
before mainlioop()
.Snippet:
import tkinter as tk
root = tk.Tk()
path = "p2.png"
photo = tk.PhotoImage(file=path)
tk.Label(root,image=photo,bg='grey').pack(side = "bottom", fill = "both", expand = "yes")
#your other label or button or ...
root.wm_attributes("-transparentcolor", 'grey')
root.mainloop()
screenshot:
Upvotes: 0