我已经尝试过尽可能多的线程组合。
(wxPython" Frame1"使用wxFormBuilder创建)
这似乎应该可行,但它只是崩溃了:
import wx
import wx.richtext
import time
import threading
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 )
bSizer3 = wx.BoxSizer( wx.VERTICAL )
self.m_staticText1 = wx.StaticText( self, wx.ID_ANY, u"This is a Thingy", wx.DefaultPosition, wx.DefaultSize, 0 )
self.m_staticText1.Wrap( -1 )
bSizer3.Add( self.m_staticText1, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5 )
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 )
bSizer3.Add( self.m_richText1, 1, wx.EXPAND |wx.ALL, 5 )
self.m_button2 = wx.Button( self, wx.ID_ANY, u"MyButton", wx.DefaultPosition, wx.DefaultSize, 0 )
bSizer3.Add( self.m_button2, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5 )
self.SetSizer( bSizer3 )
self.Layout()
self.Centre( wx.BOTH )
def __del__( self ):
pass
class Main(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
app = wx.App()
frame = MyFrame1(None)
frame.Show()
app.MainLoop()
if __name__ == "__main__":
print "Starting Thread!"
t = Main()
t.start()
time.sleep(1)
print "This should print while the window is open!"
崩溃对话:
Python quit unexpectedly while using the libwx_osx_cocoau-3.0.0.1.0.dylib plug-in.
我浏览了很多帖子,阅读了"Non-Blocking Gui documentation"。它没有点击我。
答案 0 :(得分:2)
OSX要求GUI保留在主线程中。