如何更改按钮边框的颜色

时间:2018-11-01 12:29:39

标签: python tkinter widget

如何在tkinter中更改边框的颜色

我查看了推荐使用highlightcolorhighlightbackground的其他解决方案,但是这些解决方案无效。

excercises_button = Button(canvas, width=327, height=150, image=dumbell_img,borderwidth=4, relief="ridge", bg = "gray55", command = Excercises)
canvas_excercises_button = canvas.create_window(168, 724, window=excercises_button)

我希望此按钮的边框为橙色。

这是当前的样子: https://i.stack.imgur.com/3QX8X.png

2 个答案:

答案 0 :(得分:1)

这里是一个示例,说明如何使用框架和按钮创建一种边框。

import tkinter as tk

root = tk.Tk()

frame = tk.Frame(root, highlightbackground="orange", highlightcolor="orange", highlightthickness=4, bd=0)
frame.grid(row=0, column=0)
# adding weights so the button is center on the frame.
frame.columnconfigure(0, weight=1)
frame.rowconfigure(0, weight=1)

btn = tk.Button(frame,text="test", borderwidth=4, relief="ridge", bg = "gray55").grid(row=0, column=0)
root.mainloop()

结果:

enter image description here

答案 1 :(得分:1)

我找到了解决方法!

我所做的是我创建了一个包围按钮的矩形。

canvas.create_rectangle(0, 638, 1100, 900, fill=colour)

然后我将三个按钮缩小了几个像素,以显示矩形的背景。

相关问题