首页 > 解决方案 > 将鼠标悬停在 Tkinter 中的按钮上时如何停止颜色变化?

问题描述

i我不想将颜色更改为其他任何颜色。我希望按钮在悬停在其上时不会将颜色更改为浅灰色。有没有办法在 Tkinter 中做到这一点。

from tkinter import *

window = Tk()

button = Button(window, text="ok", fg='white', bg='black')

button.grid(row=0, column=0, padx=0, pady=0)

window.mainloop()

顺便说一下,我使用的是 Ubuntu 20.04

标签: python-3.xtkinter

解决方案


您可以将activeforeground颜色设置为与颜色相同,将fg颜色设置为与activebackground颜色相同bg

button = Button(window, text="ok", fg='white', bg='black',
                activeforeground='white', activebackground='black')

推荐阅读