如何更改tkinter小部件的边框颜色?

问题描述 投票:0回答:1

我一直在尝试在Tkinter中配置小部件的边框颜色,我想知道如何做到这一点...。

我已经检查了StackOverflow,它说我应该使用configure选项,然后设置highlightbackgroundcolor = {insert color here}。我已经尝试过了,但没有任何效果。有人可以给我看看代码的工作示例,以便我找出来吗?

python tkinter widget ttk
1个回答
2
投票

无法更改窗口小部件的边框颜色,边界颜色与窗口小部件的背景颜色相关。相反,您可以关闭边框,然后使用框架小部件来设置框架的背景颜色。

screenshot

import tkinter as tk

root = tk.Tk()

label_border = tk.Frame(root, background="red")
label = tk.Label(label_border, text="This has a red border", bd=0)
label.pack(fill="both", expand=True, padx=1, pady=1 )

label_border.pack(padx=20, pady=20)

root.mainloop()
© www.soinside.com 2019 - 2024. All rights reserved.