简体   繁体   English

wxPython RichTextCtrl比tkInter Text慢得多?

[英]wxPython RichTextCtrl much slower than tkInter Text?

I've made a small tool that parses a chunk of text, does some simple processing (retrieves values from a dictionary, a few regex, etc.) and then spits the results. 我已经制作了一个小工具,可以分析大量文本,进行一些简单的处理(从字典中检索值,一些正则表达式等),然后吐出结果。

In order to make easier to read the results, I made two graphic ports, one with tkInter and other with wxPython, so the output is nicely displayed in a Text Area with some words having different colours. 为了使结果更容易阅读,我制作了两个图形端口,一个使用tkInter,另一个使用wxPython,因此输出很好地显示在Text Area中,其中的某些单词具有不同的颜色。

The tkInter implementation uses Tkinter.Text object and to apply the colours to the words uses tags (configured with the method Tkinter.Text.tag_config and passing them to Tkinter.Text.insert ), and the measured while outputting about 400 different coloured words is < 0.02s. tkInter实现使用Tkinter.Text对象,并将颜色应用于单词Tkinter.Text.tag_config标签(使用方法Tkinter.Text.tag_config配置并将它们传递给Tkinter.Text.insert ),在输出约400个不同颜色的单词时测得的结果是<0.02秒。

The wxPython implementation uses wx.richtext.RichTextCtrl and to apply the colours to the words uses wx.richtext.RichTextCtrl.BeginTextColour and then wx.richtext.RichTextCtrl.AppendText ; wxPython实现使用wx.richtext.RichTextCtrl ,将颜色应用于单词使用wx.richtext.RichTextCtrl.BeginTextColour然后是wx.richtext.RichTextCtrl.AppendText the performance is ridiculous, it takes abut 1.4s to do the same job that only took 0.02s to the tkInter port. 性能太可笑了,大约花1.4s就能完成只花0.02s到tkInter端口的相同工作。

Is this an intrinsic problem of the RichTextCtrl widget, the wxPython bindings, or there is some way to speed it up? 这是RichTextCtrl小部件,wxPython绑定的固有问题,还是有某种方法可以加快它的速度?

Thanks! 谢谢!

I'm copying here the comment that solved the problem: 我在这里复制解决问题的评论:

Have you tried using Freeze() and Thaw() to only update the display after you are done appending the coloured text? 您是否尝试过使用Freeze()和Thaw()解冻仅在添加彩色文本后更新显示内容? – mghie Jun 30 at 7:20 – mghie 6月30日7:20

有点避免了这个问题,但是您可以改用wxStyledTextCtrl吗?

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

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