问题描述
限时送ChatGPT账号..我一直在尝试在 Tkinter 中配置小部件的边框颜色,我想知道如何做到这一点....
I've been trying to configure the border colour of a widget in Tkinter, and I was wondering how to do that....
我检查了 StackOverflow,它说我应该使用 configure
选项,然后设置 highlightbackgroundcolor = {insert color here}
.我已经尝试过了,但没有任何效果.有人可以向我展示一个有效的代码示例,以便我弄清楚吗?
I've checked on StackOverflow, and it says that I should use the configure
option and then set highlightbackgroundcolor = {insert color here}
. I've tried that and nothing has worked. Can someone please show me a working sample of code so I can figure it out?
推荐答案
没有办法改变小部件的边框颜色,边框颜色与小部件的背景颜色绑定.相反,您可以关闭边框,然后使用框架小部件,您可以在其中设置框架的背景颜色.
There is no way to change the border color of a widget, the border color is tied to the background color of the widget. Instead, you can turn off the border, and then use a frame widget where you can set the background color of the frame.
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()
这篇关于如何更改 tkinter 小部件的边框颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论