简体   繁体   English

Tkinter文本小部件:配置字体

[英]Tkinter Text widget: Configure font

I have Text widget that I can configure the font families by: 我有Text小部件,可以通过以下方式配置字体系列:

textwidget.config(font=(Consolas,13))

That would configure the whole text Widget. 这将配置整个text Widget。 I only want to tell Tkinter I want to make every input after the Text widget has been configured to be like how I changed it. 我只想告诉Tkinter我想在将Text小部件配置为类似于我对其进行更改后进行的所有输入。

How can I achieve this. 我该如何实现。 Thanks for any help !! 谢谢你的帮助 !!

Have a look at the tag commands. 看一下tag命令。 You can change the selected text using this code: 您可以使用以下代码更改所选文本:

number=0
def fontchange():
    textwidget.tag_add(str(number), SEL_FIRST, SEL_LAST)
    textwidget.tag_config(str(number), font=(Consolas,13))
    number += 1

Obviously this is a very basic changer but if you want to change it to the end you could change the SEL_LAST to END. 显然,这是一个非常基本的更改器,但是如果要将其更改为末尾,则可以将SEL_LAST更改为END。 Read this site for more info on tags. 阅读此站点以获取有关标签的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM