2014-09-03 3 views
-1

wxPython을 처음 사용했습니다. 파일에 여러 레코드가 있고 각 레코드를 파일에서 읽고 다른 프레임에 표시해야합니다. for 루프에서 프레임을 만들려고하지만 첫 번째 프레임이 삭제 된 후에 만 ​​두 번째 프레임을 만들길 원합니다. 아래는 내 코드입니다 :for 루프 wxPython에서 다중 프레임 만들기

import wx 
import textentry 

class Frame(wx.Frame): 
    def __init__(self, fargs, **kwargs): 
     wx.Frame.__init__(self, fargs, **kwargs) 
     #self.Bind(wx.EVT_CLOSE, self.OnClose) 
     self.panel = wx.Panel(self) 
     self.box = wx.BoxSizer(wx.VERTICAL) 

     self.m_text = wx.StaticText(self.panel, -1, label = suggested.lstrip()) 
     self.m_text.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD)) 
     self.m_text.SetSize(self.m_text.GetBestSize()) 
     self.box.Add(self.m_text, 0, wx.ALL, 10) 


     self.filler_text = wx.StaticText(self.panel, -1, "************ Description ****************") 
     self.filler_text.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD)) 
     self.filler_text.SetSize(self.filler_text.GetBestSize()) 
     self.box.Add(self.filler_text, 0, wx.ALL, 10) 



     self.d_text = wx.StaticText(self.panel, -1, label = description.lstrip()) 
     self.d_text.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD)) 
     self.d_text.SetSize(self.d_text.GetBestSize()) 
     self.box.Add(self.d_text, 0, wx.ALL, 10) 

     self.m_close = wx.Button(self.panel, wx.ID_EDIT, "Edit") 
     self.m_close.Bind(wx.EVT_BUTTON, self.onReject) 
     self.box.Add(self.m_close, 0, wx.ALL, 10) 

     self.m_skip = wx.Button(self.panel, wx.ID_EDIT, "Skip") 
     self.m_skip.Bind(wx.EVT_BUTTON, self.onSkip) 
     self.box.Add(self.m_skip, 0, wx.ALL, 10) 

     self.m_accept = wx.Button(self.panel, wx.ID_YES, "Accept") 
     self.m_accept.Bind(wx.EVT_BUTTON, self.OnAccept) 
     self.box.Add(self.m_accept, 0, wx.ALL, 10) 
     self.box.SetSizeHints(self) 
     self.panel.SetSizer(self.box) 
     self.panel.Layout() 

    def onReject(self, event): 
     dialog = textentry.TextEntryDialog(None, 'Edit License Info', 'Enter License information') 
     dialog.Center() 
     dialog.SetValue(self.m_text.GetLabel()) 
     if dialog.ShowModal() == wx.ID_OK: 
      self.m_text.SetLabel(dialog.GetValue()) 
      self.box.SetSizeHints(self) 
      self.panel.Layout() 
      dialog.Destroy() 

    def onSkip(self, event): 
     self.Destroy() 

    def OnClose(self, event): 
     dlg = wx.MessageDialog(self,"Do you really want to close this application?","Confirm Exit", wx.OK|wx.CANCEL|wx.ICON_QUESTION) 
     result = dlg.ShowModal() 
     dlg.Destroy() 
     if result == wx.ID_OK: 
      self.Destroy() 

    def OnAccept(self, event): 
     f = open("AcceptedLicense.txt", "a") 
     print self.m_text.GetLabel().encode('utf-8') 
     f.write(self.m_text.GetLabel().encode('utf-8') + '\n') 
     f.close() 
     self.Destroy() 

panel ='' 
app = wx.App(False) 
f = open("License.txt", "r") 
main_message = f.read() 
f.close() 
if main_message != None: 
    for m in main_message.split('Suggested License Text:'): 
     if m != "": 
      desc = [d for d in m.split("Description:")] 
      suggested = desc[0] 
      description = desc[1] 
      top = Frame(None) 
      top.Show() 
app.MainLoop() 

This is the code I use to create multiple frames: 

if main_message != None: 
    for m in main_message.split('Suggested License Text:'): 
     if m != "": 
      desc = [d for d in m.split("Description:")] 
      suggested = desc[0] 
      description = desc[1] 
      top = Frame(None) 
      top.Show() 

어떤 도움을 많이 주시면 감사하겠습니다.

+0

질문하지 않았습니다. 코드가 오류를 생성하는 경우이를 문서화하십시오. SO는 코드 검토 서비스가 아닙니다. – user590028

답변

1

프레임이 표시되기 전에 app.MainLoop()을 시작해야합니다. 코드에서 모든 프레임은 MainLoop()이 실행되기 전에 생성되므로 프레임이 모두 한 번에 표시됩니다. 여러 개의 프레임을 만드는 대신 여러 개의 패널을 만들고 이전 패널을 숨 깁니다.

또한 프레임 생성을 제어하려면 destroy() 함수 호출 이전의 이벤트 핸들러에서 무언가를 반환하십시오. 그리고 메인 프레임에서 반환을 확인하여 다음 패널을 만듭니다.