2014-11-25 3 views
0

내 프로그램을 열 때 스플래시 화면을 표시하는 코드를 만들었습니다.제대로 스플래시 화면 닫기

def main(): 
    application = wx.App(False) 
    splash = show_splash() 
    frame = MainWindow() 
    frame.Show(True) 
    splash.Destroy() 
    application.MainLoop() 

그러나 프로그램이 닫히기 전에 스플래시 화면이 나타나고 사라집니다. 나는 두 줄의 코드로 고정하지만 추한 :

def main(): 
    application = wx.App(False) 
    splash = show_splash() 
    frame = MainWindow() 
    frame.Show(True) 
    splash.Destroy() 
    splash.Hide() 
    application.MainLoop() 
    plash.Destroy() 

내 질문은 : 나는 두 번째 코드 대신 당신에게 최고의 솔루션을 첫 번째 코드로 programm에를 닫고있을 때 왜되는 SplashScreen가 나타납니다?

답변

1

wxPython 데모를보십시오. 실제 데모 코드에는 스플래시 화면이 있습니다. 'MyApp'를 구현하고 OnInit 메서드 내에 스플래시가 만들어집니다.

내가 몇 시간 전에했던 일과 데모에서 수행 된 작업 샘플을 기반으로 한 작업 샘플입니다.

# -*- coding: utf-8 -*- 
#!/usr/bin/env python 

import wxversion 
wxversion.select('3.0-classic', True) 

import wx 
from wx.lib.mixins.inspection import InspectionMixin 

import wx.lib.sized_controls as sc 

print(wx.VERSION_STRING) 

class MySplashScreen(wx.SplashScreen): 
    def __init__(self): 
     #bmp = wx.Image(opj(os.path.abspath(os.path.join(os.path.split(__file__)[0],"bitmaps","splash.png")))).ConvertToBitmap() 
     bmp = wx.ArtProvider.GetBitmap(wx.ART_QUESTION, wx.ART_OTHER, wx.Size(64, 64)) 
     wx.SplashScreen.__init__(self, bmp, 
           wx.SPLASH_CENTER_ON_SCREEN | wx.SPLASH_TIMEOUT, # | wx.STAY_ON_TOP, 
           3000, None, -1) 

     self.Bind(wx.EVT_CLOSE, self.OnClose) 
     self.fc = wx.FutureCall(2000, self.ShowMain) 


    def OnClose(self, evt): 
     # Make sure the default handler runs too so this window gets 
     # destroyed 
     evt.Skip() 
     self.Hide() 

     # if the timer is still running then go ahead and show the 
     # main frame now 
     if self.fc.IsRunning(): 
      self.fc.Stop() 
      self.ShowMain() 

    def ShowMain(self): 
     frame = MainFrame(None, title="A sample frame") 
     frame.Show() 
     if self.fc.IsRunning(): 
      self.Raise() 



class MainFrame(sc.SizedFrame): 
    def __init__(self, *args, **kwds): 
     kwds["style"] = wx.DEFAULT_FRAME_STYLE|wx.FULL_REPAINT_ON_RESIZE|wx.TAB_TRAVERSAL 

     super(MainFrame, self).__init__(*args, **kwds) 

     self.SetTitle("A sample") 
     self.Centre(wx.BOTH) 

     paneContent = self.GetContentsPane() 

     # lets add a few controls 
     for x in range(5): 
      wx.StaticText(paneContent, -1, 'some string %s' % x) 

     paneBtn = sc.SizedPanel(paneContent) 
     paneBtn.SetSizerType('horizontal') 
     # and a few buttons 
     for x in range(3): 
      wx.Button(paneBtn, -1, 'a button %s' % x) 


     self.Fit() 


class BaseApp(wx.App, InspectionMixin): 

    """The Application, using WIT to help debugging.""" 

    def OnInit(self): 
     """ 
     Do application initialization work, e.g. define application globals. 
     """ 
     self.Init() 
     self._loginShown = False 
     splash = MySplashScreen() 

     return True 


if __name__ == '__main__': 
    app = BaseApp() 
    app.MainLoop() 
+0

감사합니다. 코드를 검토했습니다. – Coug