[英]How do I make wx.TextCtrl multi-line text update smoothly?
I'm working on an GUI program, and I use AppendText to update status in a multi-line text box(made of wx.TextCtrl). 我正在开发一个GUI程序,并使用AppendText更新多行文本框(由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()
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")
Try calling the Refresh()
method on the textCtrl
尝试在
textCtrl
上调用Refresh()
方法
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. 这是wxpython邮件列表中有关该问题的主题,您可能也对此感兴趣。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.