When creating a button with an image on it you can specify its background color to be the same as the root background color with the bg='color'
parameter so that if you have an image with transparent background the result seems nice.
However for some reason when you click on the button, there is a white flash that covers the button for as long the click happens.
I have this code:
from tkinter import Tk, Button
from PIL import Image, ImageTk
root = Tk()
root.config(bg='black')
image = Image.open('your_image_file').resize((50, 50))
image = ImageTk.PhotoImage(image)
button = Button(root, width=50, height=50, image=image, bg='black')
button.pack()
root.mainloop()
After importing PIL (if not already) and then filling the appropriate path name to your image the code should run without any problems
Notice that when you click the image a whity flash that covers the button appears?
I want to get rid of that
I've tried passing the parameters highlightcolor
highlightbackground
and highlightthickness
and playing around with them but nothing really changes whether I for example change highlightthickness=0
or highlightbackground='blue'
Is there any way to do that properly?
Thanks in advance!