37,719
社区成员
发帖
与我相关
我的任务
分享
import wx,threading
import wx.xrc
import wx.richtext
import time
class MainThread(threading.Thread):
def __init__(self,window):
threading.Thread.__init__(self)
self.window=window
def run(self):
self.window.DoTest()
class MyFrame1 ( wx.Frame ):
def __init__( self, parent ):
wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
bSizer1 = wx.BoxSizer( wx.VERTICAL )
self.m_richText1 = wx.richtext.RichTextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0|wx.VSCROLL|wx.HSCROLL|wx.NO_BORDER|wx.WANTS_CHARS )
bSizer1.Add( self.m_richText1, 1, wx.EXPAND |wx.ALL, 5 )
self.SetSizer( bSizer1 )
self.Layout()
self.Centre( wx.BOTH )
def __del__( self ):
pass
def DoTest(self):
while True:
self.m_richText1.AppendText('hello\n')
time.sleep(1)
def Start(self):
self.mainthread=MainThread(self)
self.mainthread.setDaemon(True)
self.mainthread.start()
if __name__=='__main__':
app=wx.PySimpleApp()
my=MyFrame1(None)
my.Show()
my.Start()
app.MainLoop()
# -*- coding: utf-8 -*-
import wx,threading
import wx.xrc
import wx.richtext
import time
class MainThread(threading.Thread):
def __init__(self,window):
threading.Thread.__init__(self)
self.window=window
def run(self):
while True:
wx.CallAfter(self.window.DoTest())
time.sleep(1)
class MyFrame1 ( wx.Frame ):
def __init__( self, parent ):
wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
bSizer1 = wx.BoxSizer( wx.VERTICAL )
self.m_richText1 = wx.richtext.RichTextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0|wx.VSCROLL|wx.HSCROLL|wx.NO_BORDER|wx.WANTS_CHARS )
bSizer1.Add( self.m_richText1, 1, wx.EXPAND |wx.ALL, 5 )
self.SetSizer( bSizer1 )
self.Layout()
self.Centre( wx.BOTH )
def __del__( self ):
pass
def DoTest(self):
self.m_richText1.AppendText('hello\n')
def Start(self):
self.mainthread=MainThread(self)
self.mainthread.setDaemon(True)
self.mainthread.start()
if __name__=='__main__':
app=wx.PySimpleApp()
my=MyFrame1(None)
my.Show()
my.Start()
app.MainLoop()