2014-11-25 50 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與第一碼和你有一個最佳的解決方案,而不是第二個碼的出現?

回答

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 2014-11-28 07:48:49