如何在字典中为单个文本添加下划线(HTML中的内联样式),以便在Tkinter GUI中显示?

2024-09-30 02:15:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用python词典编写一本英语到我的母语词典。在使用键值对时,我希望能够在值中设置某些单词的样式,例如,第一个值中大写的单词。我试图在目标文本之前的“\033[1m”和之后的“\033[0m”之前添加ANSI转义序列,但仍然不起作用;相反,序列代码是打印出来的。 我该怎么做?谢谢。下面是这本词典的摘录:

#Dictionary
exlist={
    "drum":"\033[1m DRUM \033[0m: (with skin) ŋgɔ̀m; (long, single-headed, skin-covered) ɨbûm ŋgɔ̀m; (with one end) ŋgɔ̀m ə̀tu", 
    "bag":"BAG: (n) ə̀bàmɨ̀ pl. ɨ̀bàmɨ̀; (assp) (fibre bag) ə̀bàmɨ̀ tɨswé; (a type of bag made of animal skin) ndoŋ",
    "ant":"ANT: ɨgwírɨ́ (pl. əgwirɨ); (has a big croup) ɨgwírɨ́ ndiŋ; (ant species, very small, attack and destroy white ants)"
}

Tags: of文本目标with样式单词词典键值
1条回答
网友
1楼 · 发布于 2024-09-30 02:15:58

这是如何在Tkinter中加粗/下划线/斜体文本:

from tkinter import *

root = Tk()

thing1 = Label(root, text='Bolded', font=("Roberto 50 bold"))
thing1.pack()

thing2 = Label(root, text='Underlined', font=("Roberto 50 underline"))
thing2.pack()

thing3 = Label(root, text='Italiced', font=("Roberto 50 italic"))
thing3.pack()

mainloop()

相关问题 更多 >

    热门问题