问题描述
限时送ChatGPT账号..我之前尝试使用 ANSI 转义序列\033[1m"在 Tkinter 的 ListBox 中放入一个字符串,并在之后使用 ANSI 转义序列\033[0m".
I tried to put a string in ListBox in Tkinter using ANSI escape sequence "\033[1m" before, and using ANSI escape sequence "\033[0m" after .
l = Listbox(root, width=33,font = ('Arial', 15))
a="aaaabc"
l.insert(END,"\033[1m" + a[0:r] + "\033[0m"+a[r:]")
我得到的是
SyntaxError: f-string expression part cannot include a backslash
推荐答案
您不能在列表框中使用 ANSI 转义序列,也没有任何方法可以更改项目中仅某些字符的属性.
You cannot use ANSI escape sequences in the listbox, nor is there any way to change the attributes of only some characters in an item.
如果您需要富格式,则需要使用支持富格式的小部件.唯一实用的选择是 Text
小部件,这意味着您必须提供自己的绑定以使其表现得像列表框.
If you need to have rich formatting, you will need to use a widget that supports rich formatting. The only practical choice is a Text
widget, which means you'll have to supply your own bindings to make it behave like a listbox.
这篇关于如何在 ListBox Tkinter 中将字符串 fith 前 r 个字符加粗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论