I am making a GUI using tkinter, I have some Button icons on my screen, that when user clicks, they execute their specific function. for example this one:
def screenshot():
# root.iconify()
myScreentshot=pyautogui.screenshot()
file_path=filedialog.asksaveasfilename(defaultextension='.png')
myScreentshot.save(file_path)
screenshot_image = tk.PhotoImage(file='images/app6.png')
screenshot = tk.Button(root,image=screenshot_image,bg='#0000CD',command=screenshot)
screenshot.place(x=640,y=500)
the problem is icons image. when I use the image as a button icon on my page, they always have a square or a rectangle on their background, although I use bg
to set its color like my main page but I can still see it has a background.
How can I simply display the shape of the image without the background of the shape?
CodePudding user response:
The square or rectangle is called the "relief". It is one of the visual cues that this is a button that can be pressed.
If you don't want that, set it to "flat":
screenshot = tk.Button(
root,
image=screenshot_image,
relief="flat",
bg='#0000CD',
command=screenshot
)
I would however advise you not to do this. The relief is there so that buttons are recognizable as such. Removing that in some places makes for an inconsistant user interface which can confuse new users.