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

编程入门 行业动态 更新时间:2024-10-26 04:32:18
本文介绍了如何更改 tkinter 小部件的边框颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-30 08:25:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1391423.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:边框   部件   如何更改   颜色   tkinter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!