2012-04-25 83 views
0

我在我的python程序中有一個小問題,我在wxpython中工作,我試圖通過一個按鈕連接到一個函數通過事件「checkpipe」。問題是,當我按一下按鈕,蟒蛇錯誤翻譯告訴我:python錯誤︰方法需要剛好1參數(2給出)

class fenetre(wx.Frame): #on va creer une nouvelle classe pour l'interface 
    def __init__(self, parent, id): #constructeur 
     filecontent = "" 
     wx.Frame.__init__(self, parent, id, 'Solution 1 ---> Destinataire', size = (640,480)) 
     panel = wx.Panel(self) 
     verifybutton = wx.Button(panel,label = "Verifier", pos = (320,10), size = (80,30)) 
     self.currentDirectory = os.getcwd() #trouver le chemin du dossier dans lequel on se trouve 
     self.Centre() #faire apparaitre la fenetre au centre 
     textprocessid = wx.StaticText(panel, -1, monid, pos = (400, 213)) 
     self.Bind(wx.EVT_BUTTON, self.checkpipe, verifybutton) 


    def alertMessagePipeEmpty(self): 
     dialog = wx.MessageDialog(self, "Rien recu. Veuillez essayer plus tard","Erreur", wx.OK|wx.ICON_ERROR) 
     result = dialog.ShowModal() 
     dialog.Destroy() 

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

    def checkpipe(self,names = None): 
     if not os.path.exists(fifoname): 
      os.mkfifo(fifoname) 
     pipein = open(fifoname, 'r') 
     contenu = pipein.read() 
     if contenu == "": 
      self.alertMessagePipeEmpty() 
     else: 
      dialog = wx.MessageDialog(self, "Vous avez un fichier a recevoir. Voulez-vous le sauvegarder","Fichier recu", wx.YES_DEFAULT|wx.ICON_ERROR) 
      result = dialog.ShowModal() 
      dialog.Destroy() 
      if result == wx.ID_YES: 
       dlg = wx.FileDialog(
       self, message="Sauvegardez le fichier", 
       defaultDir=self.currentDirectory, 
       defaultFile="", 
       wildcard=wildcard, 
       style=wx.SAVE | wx.CHANGE_DIR 
       ) 
       if dlg.ShowModal() == wx.ID_OK: 
        paths = dlg.GetPaths() 
        pathcomplet = "" 
        for path in paths: 
         pathcomplet = pathcomplet + path 
       dlg.Destroy() 
       fd2 = open(pathcomplet,'w') 
       fd2.write(contenu) 
       os.unlink(fifoname) 

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

類型錯誤:checkpipe()恰恰1參數(2給出)

我都試過了,我想這是關於我錯過的一些愚蠢的事情,但我似乎無法弄清楚。任何幫助,將不勝感激。

+1

你能後的代碼一點點,好嗎?也許是來電顯示。 – CamilB 2012-04-25 10:51:13

+0

你可以發佈一些代碼嗎? – 2012-04-25 10:51:37

+1

瘋狂猜測:函數被稱爲類方法而不是靜態方法。 – MattH 2012-04-25 10:54:35

回答

4

在wx中處理事件的方法會自動將該事件作爲參數傳遞。

您應該重寫checkpipe爲: def checkpipe(self, event, names=None)

+0

我不知道wxWidgets,但我確信這就是答案。在我使用的大多數框架中都是如此:回調總是接收一個Event參數。 – CamilB 2012-04-25 11:21:33

相關問題