Transparent Backgrounds on Buttons in Tkinter Transparent Backgrounds on Buttons in Tkinter tkinter tkinter

Transparent Backgrounds on Buttons in Tkinter


The solution is a bit tricky as you need to go around using PIL but works. Just solved it after 2h of fighting.

You need to use PIL as an image loader and then pass the image to tkinter BUT with the usage of the root (main tk.Tk() class object) - without that the image won't be visible as it's gone in the garbage collector, only image's space remains. Simplified code below:

import tkinter as tkfrom PIL import Image, ImageTkroot = tk.Tk()button = tk.Button(self.left_menu)        button_load = Image.open('assets/search.png')        root.button_img = ImageTk.PhotoImage(button_load)        button.config(image=root.button_img)           button_1.pack(side='top')


If you are using a .png with import PIL python is supporting the transparency.

However, within tkinter the .Button widget does not support transparency.

So what you will have is transparent image on top of a solid background.

If you are a windows user, your best bet is this solution:

Transparent background in a Tkinter window