如何使标签背景在 tkinter 中不可见

乘风 python 202

原文标题How to make the Label background invisible in tkinter

我正在用 python 和 tkinter 编写一个程序,我需要一个带有不可见 bg 的标签
我该怎么做?
from tkinter import *
win=Tk()
l1 = Label(win, text="hello world!")
l1.place(x=10,y=10)
l2 = Label(win, text="------------")
l2.place(x=10,y=8)
win.mainloop()

在此处输入图像描述

从上图中可以看出,l2 在 l1 上,但 bg 实现了这一点,但我希望“文本”在 l1 上。

原文链接:https://stackoverflow.com//questions/71464072/how-to-make-the-label-background-invisible-in-tkinter

回复

我来回复
  • acw1668的头像
    acw1668 评论

    tkinter 不支持透明背景。但是,如果您只想要文本下方的一行,则可以启用underline字体选项:

    from tkinter import *
    
    win = Tk()
    
    l1 = Label(win, text='hello world!', font='arial 12 underline')
    l1.place(x=10, y=10)
    
    win.mainloop()
    

    结果

    enter image description here


    如果你想在文本顶部有一行,你可以使用overstrike字体选项来代替:

    from tkinter import *
    
    win = Tk()
    
    l1 = Label(win, text='hello world!', font='arial 12 overstrike')
    l1.place(x=10, y=10)
    
    win.mainloop()
    

    结果

    enter image description here

    2年前 0条评论