1 year ago
#153031
user9468014
Tkinter custom button with transparent button background
I'm trying to find a solution to make the background of my image-button transparent. I can come up with a solution with create_image but i need to be able to add text to the buttons. It looks like the image png transparency is supported but the grey you can see is from the button background itself.
Here is an example code:
import tkinter as tk
from PIL import Image, ImageTk
def quitGame(event):
window.destroy()
window = tk.Tk()
window.geometry("500x500")
canvas = tk.Canvas(window, width = 300, height = 300)
canvas.pack()
bgImage = ImageTk.PhotoImage(Image.open("assets/node_button.png"))
button = tk.Button(text='TEST BUTTON', command=lambda: print(f'pressed button'), image=bgImage,
borderwidth=0, bg='white', highlightthickness=0, relief='flat',
activebackground='white', compound='center', fg='white')
button_id = canvas.create_window(1, 1, anchor='nw',
window=button, width=100, height=40)
button.bind('<B1-Motion>', quitGame)
window.mainloop()
Anyone knows a way around this problem?
tkinter
button
transparent
0 Answers
Your Answer