0

I've created a short and simple program just for placing a round TKinter image button on top of a label and see if it functions well. So far it works for what it's supposed to do (in this case printing "Hello World" whenever I press the button), but the one thing that bothers me is the white box that appears around the image when placed on the label.

While I did try to change the background color of the button to be the same as the label's, the white box still shows up whenever I click on the button and only disappears after letting go. I want to make sure that the white box is completely gone, but I'm not sure what changes I have to make to my code to make it possible. The following code is what I've done so far, plus a photo of the execution, open to any suggestions.

from tkinter import *
import tkinter as tk

class CustomButton:
    def __init__(self):
        self.root = Tk()
        self.root.configure(width=470,height=550)
        self.loadimage = PhotoImage(file="C://Users//UserPC//Pictures//chat2_resized.png")
        self.labelBottom = Label(self.root,bg="#ABB2B9",height=80)
        self.labelBottom.place(relwidth=1,rely=0.825)
        self.roundButton = Button(self.labelBottom, image=self.loadimage,
                                  command=lambda: print("Hello World"))
        self.roundButton["border"] = 0
        self.roundButton.pack(side="top")
        self.roundButton.place(relx = 0.77,rely=0.008)
        self.root.mainloop()

win = CustomButton()
win.start()

This is an example of the run. As you can see, there's a white box around the image button that I want to remove. Even if I change the background color of it, the white box still appears when I click on it.

enter image description here

Random Davis
  • 6,662
  • 4
  • 14
  • 24
  • Does this answer your question? [Display an image with transparency and no background or window in Python](https://stackoverflow.com/questions/71416368/display-an-image-with-transparency-and-no-background-or-window-in-python) – Random Davis Aug 29 '23 at 15:51
  • Why do you have two duplicates layout manager `self.roundButton.pack(side="top")` and `self.roundButton.place(relx = 0.77,rely=0.008)`? – toyota Supra Aug 29 '23 at 20:14
  • Use same color from `self.labelBottom`. self.roundButton = Button(self.labelBottom, bg="#ABB2B9", .... – toyota Supra Aug 29 '23 at 20:20
  • tkinter `Label` is not designed to be a container of other widgets, although it can be. Use `Frame` instead. – acw1668 Aug 30 '23 at 01:14

1 Answers1

0

Set highlightthickness to 0 on your button.

self.roundButton = Button(self.labelBottom,image=self.loadimage, highlightthickness=0, command=lambda: print("Hello World"))
OneMadGypsy
  • 4,640
  • 3
  • 10
  • 26