No way to color the border of a Tkinter Button?

岁酱吖の 提交于 2020-02-02 04:06:26

问题


It works with some other widgets, but not with Buttons.

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:


I am using linux and when I run your code, I get a button with a thick red border, so it looks like that the default Windows theme does not support highlightthickness while the default linux theme does.

If you want to change the border color, it is possible with some ttk themes like 'clam':

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()

However, changing the borderwidth, with style.configure('my.TButton', borderwidth=10) does not increase the width of the red border as expected.



来源:https://stackoverflow.com/questions/47352833/no-way-to-color-the-border-of-a-tkinter-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!