Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 正确关闭启动屏幕_Python_Wxpython_Splash Screen - Fatal编程技术网

Python 正确关闭启动屏幕

Python 正确关闭启动屏幕,python,wxpython,splash-screen,Python,Wxpython,Splash Screen,我做了一个代码,当我的程序打开时显示一个启动屏幕 def main(): application = wx.App(False) splash = show_splash() frame = MainWindow() frame.Show(True) splash.Destroy() application.MainLoop() 但是,在程序关闭之前,启动屏幕出现并消失。 我用两行代码修复了它,但它很难看: def main(): app

我做了一个代码,当我的程序打开时显示一个启动屏幕

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()

我的问题是:当我用第一个代码关闭程序时,为什么会出现splashscreen,让您有一个最好的解决方案而不是第二个代码?

看看wxPython演示。实际的演示代码有一个启动屏幕。它实现了一个“MyApp”,并在OnInit方法中创建了splash

这里是一个基于我前一段时间做的一些事情和演示中所做的工作的示例

# -*- 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()