我有两个这样的模块(非常非常简单):
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不起作用(正如人们所期待的那样)。
所以,我的问题是,我需要在代码中更改哪些方法来使事件方法或其他方法可以从另一个模块访问?