如何在一个字符串中使用多种字体,python,tkinter

huangapple go评论64阅读模式
英文:

How to make multiple Fonts in one string, python, tkinter

问题

在Tkinter中,我想在一个Label中使用不同的字体。实际情况是这样的:我有一个Text Widget,在文本窗口中有一堆Label,每个Label包含三行:标题,时长 - 频道和描述。我想通过加粗标题来突出显示它。这可以实现吗?到目前为止,我没有找到能帮助我的信息,而且在过去我遇到了这个问题,也没有找到解决方法。

我宁愿不使用3个标签,因为标签周围有漂亮的边框。这会让事情变得更加复杂。

当然,如果必要的话,我不介意有一点复杂性,但如果不必要,那就更好了。这似乎应该是正常的功能,就像一些标签之类的。

英文:

In Tkinter, I would like to have different fonts in one Label.
So, the practical case is this: I have a Text Widget and in the text widget there is a bunch of Labels, each containing three lines: Title, Duration - Channel, and Description.
I would like to make the Title stand out by making it bold. Can this be done? So far I didn't find information that helped me out, and in the past I encountered the issue and didn't manage to find a solution.

I would prefer not to have 3 labels, because I have nice borders around the label. It would really complicate things.

Of course, I don't mind a bit of complication if it is necesary, but if it is unnecesary, then that would be nice. It seems like it should be normal functionality, like some tags <b></b> or so.

答案1

得分: 2

你不能在一个标签中使用多种字体。如果需要多种字体,您需要使用CanvasText小部件,或在一个框架内组合多个标签。可以说,最简单的解决方案将是一个三行文本小部件。

英文:

You can't use more than one font in a label. If you need multiple fonts you'll have to use a Canvas or a Text widget, or combine multiple labels inside a frame. Arguably, the simplest solution will be a three line text widget.

huangapple
  • 本文由 发表于 2023年2月10日 06:27:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/75405099.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定