如何在 ListBox Tkinter 中将字符串 fith 前 r 个字符加粗?

编程入门 行业动态 更新时间:2024-10-25 06:31:51
本文介绍了如何在 ListBox Tkinter 中将字符串 fith 前 r 个字符加粗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

本文发布于:2023-04-30 06:14:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1390791.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   中将   字符   加粗   如何在

发布评论

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

>www.elefans.com

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