in my Text widget I have here and there many tags, taking care of the text appearance (bold, italic etc).
Tkinter takes care by default of cut/copy/paste in the text widget,开发者_Go百科 but only of the text content, not of the associated tags. Do you know if it is possible to implement it?
I anticipate some problems if I would cut in the middle a region where e.g. bold text appears: I would have to leave behind a tag marker for 'bold begin' so that the remaining text is still bold...
Yes, it's possible to implement it. You can use the dump
method of the text widget to get all the text and tags in a given range. To paste, you just have to use that information when inserting the text.
It gets somewhat complicated when you try to paste, say, italic text inside a range of already bolded text since you may have to retag the inserted text to have both bold and italic attributes. However, I know it can be done because I've done it with tcl/tk in the past.
精彩评论