wx.richtext.RichTextCtrl real-time display text

Hi, there,

I want to use wx.richtext.RichTextCtrl to display real-time(running-time) texts. But it seems wx.richtext.RichTextCtrl can not display texts until the task is done, please look at the following sample code. Did I miss something? However, I tried wx.TextCtrl and it can display texts during running time without any problem. In following code, you can switch two self.log to see difference.

Your clue is appreciated.

Eddy H.

import wx

import wx.richtext

import sys

class MyForm(wx.Frame):

def init(self):

wx.Frame.init(self, None, wx.ID_ANY, “wxPython Redirect Tutorial”)

Add a panel so it looks the correct on all platforms

panel = wx.Panel(self, wx.ID_ANY)

self.log = wx.richtext.RichTextCtrl(panel, wx.ID_ANY, size=(300,100), style = wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)

#self.log = wx.TextCtrl(panel, wx.ID_ANY, size=(300,100), style = wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)

btn = wx.Button(panel, wx.ID_ANY, ‘Push me!’)

self.Bind(wx.EVT_BUTTON, self.onButton, btn)

Add widgets to a sizer

sizer = wx.BoxSizer(wx.VERTICAL)

sizer.Add(self.log, 1, wx.ALL|wx.EXPAND, 5)

sizer.Add(btn, 0, wx.ALL|wx.CENTER, 5)

panel.SetSizer(sizer)

def onButton(self, event):

for i in range(3000):

self.log.WriteText(“You pressed the button!\n”)

self.Refresh();

Run the program

if name == “main”:

app = wx.App(False)

frame = MyForm().Show()

app.MainLoop()

Eddy,

Add a line

wx.Yield()

after the WriteText() line, within the “for i in range(3000):” loop.

Adrian

···

On Friday, February 3, 2017 at 9:47:05 PM UTC-7, SL Huang wrote:

Hi, there,

I want to use wx.richtext.RichTextCtrl to display real-time(running-time) texts. But it seems wx.richtext.RichTextCtrl can not display texts until the task is done, please look at the following sample code. Did I miss something? However, I tried wx.TextCtrl and it can display texts during running time without any problem. In following code, you can switch two self.log to see difference.

Your clue is appreciated.

Eddy H.

import wx

import wx.richtext

import sys

class MyForm(wx.Frame):

def init(self):

wx.Frame.init(self, None, wx.ID_ANY, “wxPython Redirect Tutorial”)

Add a panel so it looks the correct on all platforms

panel = wx.Panel(self, wx.ID_ANY)

self.log = wx.richtext.RichTextCtrl(panel, wx.ID_ANY, size=(300,100), style = wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)

#self.log = wx.TextCtrl(panel, wx.ID_ANY, size=(300,100), style = wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)

btn = wx.Button(panel, wx.ID_ANY, ‘Push me!’)

self.Bind(wx.EVT_BUTTON, self.onButton, btn)

Add widgets to a sizer

sizer = wx.BoxSizer(wx.VERTICAL)

sizer.Add(self.log, 1, wx.ALL|wx.EXPAND, 5)

sizer.Add(btn, 0, wx.ALL|wx.CENTER, 5)

panel.SetSizer(sizer)

def onButton(self, event):

for i in range(3000):

self.log.WriteText(“You pressed the button!\n”)

self.Refresh();

Run the program

if name == “main”:

app = wx.App(False)

frame = MyForm().Show()

app.MainLoop()

Hi, Adrian,

Thank you so much! That saved me lots of time to continuously search around.

Eddy

Eddy,

Add a line

wx.Yield()

after the WriteText() line, within the “for i in range(3000):” loop.

Adrian

···

On Sunday, February 5, 2017 2:40 PM, Adrian Hill hill.adrian86@gmail.com wrote:

On Friday, February 3, 2017 at 9:47:05 PM UTC-7, SL Huang wrote:

Hi, there,

I want to use wx.richtext.RichTextCtrl to display real-time(running-time) texts. But it seems wx.richtext.RichTextCtrl can not display texts until the task is done, please look at the following sample code. Did I miss something? However, I tried wx.TextCtrl and it can display texts during running time without any problem. In following code, you can switch two self.log to see difference.

Your clue is appreciated.

Eddy H.

import wx

import wx.richtext

import sys

class MyForm(wx.Frame):

def init(self):

wx.Frame.init(self, None, wx.ID_ANY, “wxPython Redirect Tutorial”)

Add a panel so it looks the correct on all platforms

panel = wx.Panel(self, wx.ID_ANY)

self.log = wx.richtext.RichTextCtrl( panel, wx.ID_ANY, size=(300,100), style = wx.TE_MULTILINE|wx.TE_ READONLY|wx.HSCROLL)

#self.log = wx.TextCtrl(panel, wx.ID_ANY, size=(300,100), style = wx.TE_MULTILINE|wx.TE_ READONLY|wx.HSCROLL)

btn = wx.Button(panel, wx.ID_ANY, ‘Push me!’)

self.Bind(wx.EVT_BUTTON, self.onButton, btn)

Add widgets to a sizer

sizer = wx.BoxSizer(wx.VERTICAL)

sizer.Add(self.log, 1, wx.ALL|wx.EXPAND, 5)

sizer.Add(btn, 0, wx.ALL|wx.CENTER, 5)

panel.SetSizer(sizer)

def onButton(self, event):

for i in range(3000):

self.log.WriteText(“You pressed the button!\n”)

self.Refresh();

Run the program

if name == “main”:

app = wx.App(False)

frame = MyForm().Show()

app.MainLoop()

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.