2012-01-24 35 views
0

我沒有得到我的代碼的任何錯誤,但是當我點擊垃圾郵件按鈕後,它凍結,沒有任何反應。有沒有人看到代碼有什麼問題?wxPython應用程序:沒有錯誤,但仍然凍結

import Skype4Py, wx, time as t 


    skype = Skype4Py.Skype() 
    skype.Attach() 
    name = "" 
    chat = "" 
    message = "" 


    class skyped(wx.Frame): 

     def __init__(self,parent,id): 
      wx.Frame.__init__(self,parent,id,"Skype Chat Spammer",size=(300,200)) 
      panel=wx.Panel(self) 
      start=wx.Button(panel,label="Spam!",pos=(140,100),size=(50,20)) 
      stop=wx.Button(panel,label="Stop!", pos=(200,100),size=(50,20)) 
      self.Bind(wx.EVT_BUTTON, self.spam, start) 
      self.Bind(wx.EVT_CLOSE, self.closewindow) 
      entered=wx.TextEntryDialog(None, "User to spam?", "User", "Username Here") 
      if entered.ShowModal()==wx.ID_OK: 
       name=entered.GetValue() 
      entered1=wx.TextEntryDialog(None, "Message?", "Message", "Message Here") 
      if entered1.ShowModal()==wx.ID_OK: 
       message=entered1.GetValue() 

     def spam(self,event): 
      global chat 
      global name 
      global message 
      chat = skype.CreateChatWith(name) 
      while 1: 
       chat.SendMessage(message) 

     def closewindow(self,event): 
      self.Destroy() 

    if __name__=="__main__": 
     app=wx.PySimpleApp() 
     frame=skyped(parent=None,id=-1) 
     frame.Show() 
     app.MainLoop() 

回答

2

大廈關閉kotlinski的回答,是其凍結,因爲你正在做的主線程死循環你的申請。該應用程序不能再處理任何與gui相關的交互或事件。

雖然我不太瞭解wx,但理論與PyQt相同。任何長時間運行或繁重的操作都不應阻塞應用程序的主線程。這些應該在單獨的線程中運行,並與信號傳送回:

http://wiki.wxpython.org/LongRunningTasks

你的主線程應始終清楚地處理與小部件的用戶交互。

+0

謝謝你這就是我一直在尋找的。 – user1152873

0

它可能凍結,因爲你的應用程序進入無限循環的位置:

while 1: 
     chat.SendMessage(message) 
+0

我想wx只是不能處理它,因爲我在它實現wx之前已經工作了。 – user1152873

+0

它不是那個wx不能處理它。它,你不能處理wx :)。當你沒有使用wx的時候,你可以看到它坐在循環中並處理,但現在你只是阻塞了主線程。你需要做的就是在一個線程中運行這個 – jdi

相關問題