Handle multiple tags in a Text widget when each tag adds a style to the text?
I want to create a toolbar for a text widget that allows you to select bold or italic text, as well as their combination (bold and italic together).
I've been looking at this response to Advanced Tkinter text box, as well as code for the StyledText widget, but neither answers my question.
The basic way to configure tags:
开发者_高级运维txtWidget.tag_configure("bold", font=my_bold_font)
txtWidget.tag_configure("italic", font=my_italic_font)
It means you can associate a single font with a single tag, but there doesn't appear to be any way (on the surface) to associate tag combinations with a font.
Is the best way to proceed to create a tag_bind event to a method that will figure out my tag combinations and assign the font accordingly, or is there another way?
Sadly, this is one of the few weaknesses of the text widget. If you want both bold and italic you need a tag with a font that has both of those attributes. You can create new tags on the fly so it's not an impossible problem to solve, but it can be a bit tedious to figure out which characters in a range need the "bold" tag, which need the "italic" tag, and which needs a new "bold_italic" tag.
精彩评论