How do I make wx.TextCtrl multi-line text update smoothly?
Solution 1
Try calling the Refresh()
method on the textCtrl
Update:
A question has already been asked regarding this problem, here is the answer which pretty much solves it, -its not perfect but maybe you can improve on it...
Here is a thread from the wxpython mailing list regarding the problem which may also be of interest to you.
Solution 2
try this:
self.logs = wx.TextCtrl(self, id=-1, value='', pos=wx.DefaultPosition,
size=(-1,300),
style= wx.TE_MULTILINE | wx.SUNKEN_BORDER)
self.logs.AppendText(text + "\n")
Shane
Updated on June 05, 2022Comments
-
Shane almost 2 years
I'm working on an GUI program, and I use AppendText to update status in a multi-line text box(made of wx.TextCtrl). I noticed each time there's a new line written in this box, instead of smoothly adding this line to the end, the whole texts in the box just disappear(not in real, just visually) and I have to click the scroll button to check the newly updated/written status line. Why this happening? Should I add some styles? Hopefully you guys can help me out.
Here's my sample code:
import wx import thread import time class TestFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, parent = None, id = -1, title = "Testing", pos=(350, 110), size=(490,530), style=wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX) panel = wx.Panel(self) self.StartButton = wx.Button(parent = panel, id = -1, label = "Start", pos = (110, 17), size = (50, 20)) self.MultiLine = wx.TextCtrl(parent = panel, id = -1, pos = (38, 70), size = (410, 90), style = wx.TE_MULTILINE|wx.TE_READONLY|wx.TE_AUTO_URL) self.Bind(wx.EVT_BUTTON, self.OnStart, self.StartButton) def OnStart(self, event): self.StartButton.Disable() thread.start_new_thread(self.LongRunning, ()) def LongRunning(self): Counter = 1 while True: self.MultiLine.AppendText("Hi," + str(Counter) + "\n") Counter = Counter + 1 time.sleep(2) class TestApp(wx.App): def OnInit(self): self.TestFrame = TestFrame() self.TestFrame.Show() self.SetTopWindow(self.TestFrame) return True def main(): App = TestApp(redirect = False) App.MainLoop() if __name__ == "__main__": main()