简体   繁体   English

如何根据文本 tkinter 中的选择更改字体?

[英]How to change the font according to selection in text tkinter?

How to change the font of the selected text in tkinter?如何更改 tkinter 中选定文本的字体? I have checked the web, but I did not get any results.我检查了 web,但没有得到任何结果。 I want the fonts in a ComboBox of tkinter.ttk .我想要 fonts 在ComboBoxtkinter.ttk中。

Please help!请帮忙!

I think you are looking for something like this:我想你正在寻找这样的东西:

text_widget.tag_add("font_1", *map(str, text_widget.tag_ranges("sel")))
text_widget.tag_config("font_1", font=...)

That will change the font of the selected text.这将更改所选文本的字体。 If you bind to the ComboBox changing and run the script, it should work.如果您绑定到ComboBox更改并运行脚本,它应该可以工作。

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

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