python - 如何让wx.TextCtrl 多行文本平滑更新?

标签 python wxpython wx.textctrl

我正在开发一个 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()

最佳答案

试试这个:

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")

关于python - 如何让wx.TextCtrl 多行文本平滑更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3566603/

相关文章:

python - ListCtrl - wxPython/Python

python - 为什么这不起作用(wxpython/颜色对话框)

python - 如何在wxpython中改变wx.TextCtrl小部件的形状?

python - 用 1 和 0 填充 DataFrame

python - 是否有一种数据类型/结构可以 : hold a list of numbers, 是可散列的、无序的并且允许重复

Python wx.stc 自定义高亮显示

python - Wx.stc.StyledTextCtrl 滚动条

python - 如何将文本输出到屏幕,同时输出面向对象的按钮 - Pygame

python - Reactor.run 卡住循环

python - 从 wx.TextCtrl 中删除行