0

Tried removing the grey outline in all kinds of ways, but it didn't work.

Using Canvas: inserting buttons into the canvas, which is supposed to give transparent buttons according to this tutorial:https://www.youtube.com/watch?v=WurCpmHtQc4

from tkinter import *
root = Tk()
root.geometry("640x480")
bg=PhotoImage(file=("beach_640_480.png"))

my_canvas= Canvas(root, width=640, height=480)
my_canvas.pack(fill="both", expand=True)
my_canvas.create_image(0,0, image=bg, anchor="nw") 
my_canvas.create_text(100,175, text="Welcome", font=("Times", 45), fill="white")

button1= Button(root, text="text1")
button1_window=my_canvas.create_window(10,10,anchor="nw", window=button1)

root.mainloop()

But it left me with the grey borders.

Trying out various button styles by changing bg, borderless, or border width in tkmacosx:


b2 = Button(root, text='Button', bg='#ADEFD1',
            fg='#00203F', borderless=1)
b2.pack(padx=20, pady=10)

And despite these attempts, these are the results: enter image description here

For reference, I am using Mac OS, and I know Tkinter is somewhat different in windows and Mac, but I am not sure where the problem with something like this is.

edit: I tried it with Tkinter tkmacosx as well, you can see the result on the left window above.

edit2: Now I tried changing the highlightthickness and still no result: enter image description here

However the outline is now black, which is likely because I switched my laptop to dark mode. So at least we found a clue? The plot thickens.

Tasin.c
  • 111
  • 6

1 Answers1

0

The grey outline around buttons in Tkinter can sometimes be caused by the default platform-specific styling. To remove the grey outline, you can try using the highlightthickness parameter to set the width of the highlight border to zero. Here's an example of how you can modify your code to remove the grey outline:

from tkinter import *

root = Tk()
root.geometry("640x480")

# Create a canvas
my_canvas = Canvas(root, width=640, height=480)
my_canvas.pack(fill="both", expand=True)

# Load the background image
bg = PhotoImage(file="beach_640_480.png")
my_canvas.create_image(0, 0, image=bg, anchor="nw")

# Create a button with zero highlight thickness
button1 = Button(root, text="text1", highlightthickness=0)
button1_window = my_canvas.create_window(10, 10, anchor="nw", window=button1)

root.mainloop()
  • Thanks. Although the code works, it doesn't seem to have removed the outline for me. You're right that there's some kind of issue in the default settings, but I can't figure out what it is. – Tasin.c Jul 25 '23 at 01:42