无法为Tkinter按钮的边框着色?

时间:2017-11-17 14:23:30

标签: python button tkinter colors widget

它适用于其他一些小部件,但不适用于按钮。

from Tkinter import *
root = Tk()
root.geometry("600x300+400+50")

btn_up = Button(root, text='Go UP')
btn_up.config(highlightbackground="red", highlightcolor="red", highlightthickness=10, relief=SOLID)
btn_up.pack()

root.mainloop()

Python 2.7 - Windows 10

1 个答案:

答案 0 :(得分:3)

我正在使用linux,当我运行你的代码时,我得到一个带有粗红色边框的按钮,所以看起来默认的Windows主题不支持highlightthickness而默认的linux主题。

screenshot

如果你想改变边框颜色,可以使用像'clam'这样的ttk主题:

from Tkinter import *
import ttk
root = Tk()

style = ttk.Style(root)
style.theme_use('clam')
style.configure('my.TButton', bordercolor="red")

ttk_button = ttk.Button(root, text='Go UP', style='my.TButton')
ttk_button.pack()

root.mainloop()

screenshot clam

但是,使用style.configure('my.TButton', borderwidth=10)更改边框宽度不会像预期的那样增加红色边框的宽度。