简体   繁体   English

使用python tkinter更改按钮边框的颜色

[英]Changing the colour of button border with python tkinter

I'm trying to change the color of my border on this button however it does nothing or gives me a grey border. 我正在尝试更改此按钮上边框的颜色,但是它什么也没做或给我一个灰色边框。

self._lqbutton = tk.Button(self._longquestionframe, 
                           text="TEST",
                           bg="blue", fg="#fff",
                           highlightbackground="red",
                           highlightcolor="red",
                           highlightthickness=4,
                           relief=tk.SOLID,
                           borderwidth="4")
self._lqbutton.pack()

I have also tried using relief=tk.FLAT 我也尝试过使用relief = tk.FLAT

You cannot change the border color of a widget. 您无法更改小部件的边框颜色。 The highlightcolor and highlightbackground attributes changes the color of the highlight ring , which is the border-like decoration that appears only when the widget has focus. highlightcolorhighlightbackground属性更改了高亮环的颜色, 高亮环是仅当小部件具有焦点时才出现的边框状装饰。

Managed to achieve the effect by placing it inside its own frame and changing the frame attributes. 通过将效果放置在自己的框架中并更改框架属性来实现效果。

self._lqbuttonborder = tk.Frame(self._longquestionframe,
                                    highlightbackground="#bce8f1",
                                    highlightcolor="#bce8f1",
                                    highlightthickness=1,
                                    bd=0)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM