我正在开发一个 GUI 程序,我使用 AppendText 在多行文本框(由 wx.TextCtrl 制成)中更新状态。我注意到每次在这个框中写下一个新行,而不是平滑地将这一行添加到末尾,框中的整个文本都会消失(不是真实的,只是视觉上的),我必须单击滚动按钮来检查新更新/写入的状态行。为什么会这样?我应该添加一些样式吗?希望你们能帮助我。
这是我的示例代码:
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()