我有一个带有一个框架的 Python GUI,该框架具有一个上面板和一个垂直拆分窗口。对于 splitterwindow 中的每个 Panel,我创建了两个 Panel 类,一个带有列表框,另一个带有网格。每个类都有几个按钮。
有没有办法将按钮连接event.bind
和功能代码保留在类中并使其工作,因为目前我收到以下错误:
AttributeError: 'Panel' object has no attribute 'm_dirPicker1'
我想知道在报告的情况下哪个是最佳实践。
这是我所写内容的一个简短示例:
class Frame ( wx.Frame ):
...
self.m_datapanel = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
self.m_filespanel = Source_Panel( self.m_splitter1)
self.m_gridpanel = Data_Viewer( self.m_splitter1)
class Source_Panel ( wx.Panel ):
...
# Connect Events
self.m_listBox.Bind( wx.EVT_LISTBOX_DCLICK, self.m_listBoxOnListBoxDClick )
self.m_clearbutton.Bind( wx.EVT_BUTTON, self.m_clearbuttonOnButtonClick )
self.m_importbutton.Bind( wx.EVT_BUTTON, self.m_importbuttonOnButtonClick )
self.m_showdata.Bind( wx.EVT_BUTTON, self.m_showdataOnButtonClick )
def __del__( self ):
pass
# Virtual event handlers, overide them in your derived class
def m_listBoxOnListBoxDClick( self, event ):
event.Skip()
def m_clearbuttonOnButtonClick( self, event ):
event.Skip()
def m_importbuttonOnButtonClick( self, event ):
src_directory = frame.m_datapanel.m_dirPicker1.GetTextCtrlValue()
def m_showdataOnButtonClick( self, event ):
event.Skip()
class Data_Viewer ( wx.Panel ):
...