如何更改 Tkinter 按钮周围框的颜色?

How to change the color of the box surrounding a Tkinter Button?

我尝试了一些我在 Whosebug 上找到的东西,例如在按钮周围放置一个框架并给它一个颜色,就像说的那样 here. I also tried some other stuff that is said 但我无法让它工作。

我正在使用 Mac OS 并且按钮是圆形的,但是它周围有一个正方形,这使得它看起来不太好。有谁知道我怎样才能让这个方块改变颜色?

这是我正在使用的代码:

empty = Button(frame, text='Opnieuw', command=clear, font=bold_font)
empty.config(width=10, fg='#009688', borderwidth=0, relief=RAISED)
empty.grid(row=11, column=0, pady=(25, 0), padx=(80, 0))

这就是我所说的正方形:按钮周围的白色正方形,没有那种绿色。

添加 Bryan Oakley 所说的内容后,执行此操作:

empty = Button(frame, text='Opnieuw', command=clear, font=bold_font)
empty.config(width=10, fg='#009688', borderwidth=0, relief=RAISED)
empty.configure(highlightbackground="#009688")
empty.grid(row=11, column=0, pady=(25, 0), padx=(80, 0))

更具体地说,这是我正在使用的代码的较大部分:

from tkinter import *
from tkinter import font as tkfont

root = Tk()
root.config(background='#009688')
root.title('Contractmaker')

# GUI stuff that takes care of the scrollbar
def on_configure(event):
    canvas.configure(scrollregion=canvas.bbox('all'))

def on_mousewheel(event):
    canvas.yview_scroll(int(event.delta), 'units')

# Create some fonts
bold_font = tkfont.Font(weight='bold')

# Create the actual GUI
canvas = Canvas(root, width=450, height=550)
canvas.config(background='#009688')
canvas.pack(side=RIGHT)

scrollbar = Scrollbar(root, command=canvas.yview)
# scrollbar.pack(side=RIGHT, fill='y')

canvas.configure(yscrollcommand=scrollbar.set)
canvas.bind('<Configure>', on_configure)
canvas.bind_all('<MouseWheel>', on_mousewheel)

frame = Frame(canvas)
frame.config(background='#009688')
canvas.create_window((0,0), window=frame)

empty = Button(frame, text='Opnieuw', font=bold_font)
empty.config(width=10, fg='#009688', borderwidth=0, relief=RAISED)
empty.configure(highlightbackground='#009688')
empty.grid(row=11, column=0, pady=(25, 0), padx=(80, 0))

root.mainloop()

这是我得到的:

有谁知道如何让按钮的白色部分保持白色而不是改变它的颜色?我正在使用 python 3.8 和 Tkinter 8.6。

那个白色区域叫做遍历高亮区域。当按钮获得键盘焦点时,它会改变颜色让用户知道。

您可以使用 highlightbackground 选项更改其非聚焦颜色,并使用 highlightcolor 更改其聚焦颜色。您可以将其设置为背景颜色以使其融入其中。

empty.configure(highlightbackground="#009588")