異なるモジュール内のイベント方法:wxPythonを:私は(非常に非常に単純化された)を、このような二つのモジュールを持って
main.py:
from window import *
class MyApp(wx.Frame):
def __init__(self, parent, label, pos, size):
wx.Frame.__init__(self, parent = parent, title = label, pos = pos, size = size)
self.Centre()
create_window(self)
self.Bind(wx.EVT_CLOSE, self.OnClose)
def OnClose(self, event):
self.dlg = wx.MessageDialog(self, 'Quit application',
'Please confirm', wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
if self.dlg.ShowModal() == wx.ID_YES:
self.Destroy()
if __name__ == '__main__':
app = wx.App()
frame = MyApp(None, 'MyApp', (0, 0), (740, 640))
frame.Show()
frame.SetFocus()
app.MainLoop()
window.py:今
import wx
def create_window(self):
self.menubar = wx.MenuBar()
self.fileMenu = wx.Menu()
self.item = self.fileMenu.Append(wx.ID_EXIT, 'Quit', 'Quit application')
self.Bind(wx.EVT_MENU, self.OnClose, self.item)
self.menubar.Append(self.fileMenu, '&File')
self.SetMenuBar(self.menubar)
self.statusbar = self.CreateStatusBar()
self.statusbar.SetStatusText('Ready')
私はOnCloseメソッドをmain.pyからwindow.pyに移動したいのですが(main.pyの他の多くのメソッドがある場合はこれだけでなく、それらをすべて別のモジュールに移動してコードをより構造化したいと思っています)。 しかし、main.pyからモジュールを切り取り、それをwindow.pyに貼り付けるだけではうまくいきません。 私の質問では、イベントメソッドや別のメソッドを他のモジュールからアクセスできるようにするために、コード内で何を変更する必要がありますか?
はcreate_windowクラス内のメソッドか、それは関数として表示されていますか? – joaquin