2017-11-13 3 views
0

wxPythonを使用してPythonでユーティリティプログラムを作成していますが、ボタンにメソッドをバインドできません。イベントハンドラをボタンにバインドできない

興味深いのは、別のボタン(self.add_employee_to_list)をまったく同じ方法でバインドしていますが、それは機能します。

class MyDialog(wx.Frame): 

    def __init__(self, parent, title): 
     self.no_resize = wx.DEFAULT_FRAME_STYLE & ~ (wx.RESIZE_BORDER | wx.MAXIMIZE_BOX) 
     wx.Frame.__init__(self, parent, title=title, size=(500, 450),style = self.no_resize) 

     self.panel = wx.Panel(self, size=(250, 270)) 

     self.add_employee_to_list = wx.Button(self.panel, label="Add Employee", pos=(250,50), size=(115,25)) 
     self.add_employee_to_list.Bind(wx.EVT_BUTTON, self.add_employee_to_box) 

     #Button that produces error on binding 
     self.remove_employee_from_list = wx.Button(self.panel, label="Remove Employee",pos= (250,80), size=(115,25)) 
     self.remove_employee_from_list.Bind(wx.EVT_BUTTON, self.remove_employee_from_list) 


    def remove_employee_from_list(self, event): 
     pass 

app = wx.App(False) 
frame = MyDialog(None, "Crystal Rose") 
app.MainLoop() 

私は次のエラーを取得する:

Traceback (most recent call last): File "C:/Users/SR/PycharmProjects/CrystalRose/CrystalRoseGUI.py", line 59, in <module> 
    frame = MyDialog(None, "Crystal Rose") File "C:/Users/SR/PycharmProjects/CrystalRose/CrystalRoseGUI.py", line 22, in __init__ 
    self.remove_employee_from_list.Bind(wx.EVT_BUTTON, self.remove_employee_from_list) File "C:\Program Files (x86)\Python36-32\lib\site-packages\wx\core.py", line 1339, in 
_EvtHandler_Bind 
    assert callable(handler) or handler is None AssertionError 

答えて

1

あなたはメソッドとしてremove_employee_from_listを宣言しても__init__でボタンとして、それを設定しています。ボタンとその方法は同じものではなく、異なる名前が必要です。試してみてください:

import wx 

class MyDialog(wx.Frame): 

    def __init__(self, parent, title): 
     self.no_resize = wx.DEFAULT_FRAME_STYLE & ~ (wx.RESIZE_BORDER | wx.MAXIMIZE_BOX) 
     wx.Frame.__init__(self, parent, title=title, size=(500, 450),style = self.no_resize) 

     self.panel = wx.Panel(self, size=(250, 270)) 

     self.add_employee_to_list = wx.Button(self.panel, label="Add Employee", pos=(250,50), size=(115,25)) 
     self.add_employee_to_list.Bind(wx.EVT_BUTTON, self.add_employee_to_box) 

     #Button that produces error on binding 
     self.remove_employee_from_list = wx.Button(self.panel, label="Remove Employee",pos= (250,80), size=(115,25)) 
     self.remove_employee_from_list.Bind(wx.EVT_BUTTON, self.remove_employee_from_box) 


    def remove_employee_from_box(self, event): 
     pass 

    def add_employee_to_box(self, event): 
     pass 

app = wx.App(False) 
frame = MyDialog(None, "Crystal Rose") 
frame.Show() 
app.MainLoop() 
+0

SIlly間違い;)ありがとう –

関連する問題