Python tkinter带有粗体和普通文本的单一标签

编程入门 行业动态 更新时间:2024-10-27 11:21:10
本文介绍了Python tkinter带有粗体和普通文本的单一标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的问题是,如果有一种方法可以在一个ttk.label()文本中显示全文,只显示粗体字中的一些单词。 我现在正在对许多ttk.labels()应用样式,但是这种方法意味着我必须将每个标签放在另一个标签旁边,并且程序是多语言的,一些字符串不适合与窗户。 如果有办法做到这一点,对我的工作将是一个很大的优势。 Thanks。

解决方案

不,您不能更改标签小部件。如果您需要设置单个字符的样式,您需要使用一个小的 Text 小部件。

例如: $ p $ text $ tk.Text(root, (bold,font =Helvetica 12 bold) text.insert(end,Hello,1,font =Helvetica 12) text.tag_configure ) text.insert(end,world,bold) text.configure(state =disabled)

My question is if there is a way to put in a single ttk.label() a text that show the full text with only some words in the bold font like this. I am doing this right now applying styles to many ttk.labels(), but this method imply that I must position every label next to the other, and that the program is multilingual, some strings don't fit correctly with the window. If there is a way to do this, it will be a great advantage to my work. Thanks.

解决方案

No, you cannot change the attributes of only some of the characters in a Label widget. If you need to style individual character you need to use a small Text widget.

For example:

text = tk.Text(root, height=1, font="Helvetica 12") text.tag_configure("bold", font="Helvetica 12 bold") text.insert("end", "Hello, ") text.insert("end", "world", "bold") text.configure(state="disabled")

更多推荐

Python tkinter带有粗体和普通文本的单一标签

本文发布于:2023-10-06 19:26:45,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:粗体   文本   标签   Python   tkinter

发布评论

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

>www.elefans.com

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