tkinter 标签的边框 [英] Border for tkinter Label
问题描述
不是很相关,但我正在构建一个日历并且我有很多 Label 小部件,因此如果我为它们设置一些边框会更好看!
Not really relevant but i'm building a calendar and I have a lot of Label widgets, and therefore it will look alot nicer if I had some borders for them!
我已经看到您可以为其他小部件(例如按钮、条目和文本)执行此操作.
I have seen you can do this for other widgets such as Button, Entry and Text.
最小代码:
from tkinter import *
root = Tk()
L1 = Label(root, text="This")
L2 = Label(root, text="That")
L1.pack()
L2.pack()
我试过设置
highlightthickness=4
highlightcolor="black"
highlightbackground="black"
borderwidth=4
在小部件内部,但结果仍然相同.
inside the widget, but still the same result.
这甚至可以做到吗?谢谢!
Is this even possible to do? Thank you!
推荐答案
如果你想要一个边框,选项是 borderwidth
.也可以选择边框的浮雕:"flat"
, "raised"
, "sunken"
, "ridge"
、"solid"
和 "groove"
.
If you want a border, the option is borderwidth
. You can also choose the relief of the border: "flat"
, "raised"
, "sunken"
, "ridge"
, "solid"
, and "groove"
.
例如:
l1 = Label(root, text="This", borderwidth=2, relief="groove")
<小时>
注意:"ridge"
和 "groove"
需要至少两个像素的宽度才能正确渲染
Note: "ridge"
and "groove"
require at least two pixels of width to render properly
这篇关于tkinter 标签的边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!