다른 모듈에서 이벤트있어서의 wxPython : I는 (아주 단순화) 다음과 같은 두 개의 모듈이
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