1

これは私が書いたコードです。ウィンドウは閉じますが、テキストは表示されません。テキストを表示してから、ウィンドウを自動的に閉じる必要があります。それが機能するためにどのような変更を加える必要がありますか ありがとう

ここにコードがあります

import wx
from time import sleep

class Frame(wx.Frame):
    def __init__(self, title):
        wx.Frame.__init__(self, None, title=title, size=(300,200))

        self.panel = wx.Panel(self)
        box = wx.BoxSizer(wx.VERTICAL)
        m_text = wx.StaticText(self.panel, -1, 'File Uploaded!')
        m_text.SetSize(m_text.GetBestSize())

        box.Add(m_text, 0, wx.ALL, 10)
        self.panel.SetSizer(box)
        self.panel.Layout()
        self.Bind(wx.EVT_ACTIVATE, self.onClose)

    def onClose(self, event):
        sleep(5)
        self.Destroy()

app = wx.App(redirect=True)
top = Frame('test')
top.Show()
app.MainLoop()
4

2 に答える 2

2

wx.Timer の使用をお勧めします。time.sleep() を使用すると、wxPython のメイン ループがブロックされ、アプリケーションが応答しなくなります。タイマーを使用するように変更されたコードは次のとおりです。

import wx

class Frame(wx.Frame):
    def __init__(self, title):
        wx.Frame.__init__(self, None, title=title, size=(300,200))

        self.panel = wx.Panel(self)
        box = wx.BoxSizer(wx.VERTICAL)
        m_text = wx.StaticText(self.panel, -1, 'File Uploaded!')
        m_text.SetSize(m_text.GetBestSize())

        box.Add(m_text, 0, wx.ALL, 10)
        self.panel.SetSizer(box)
        self.panel.Layout()

        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.onClose, self.timer)
        self.timer.Start(5000)

    def onClose(self, event):
        self.Close()

app = wx.App(redirect=True)
top = Frame('test')
top.Show()
app.MainLoop()

タイマーの詳細については、次の記事を参照してください。

http://www.blog.pythonlibrary.org/2009/08/25/wxpython-using-wx-timers/

于 2013-10-08T15:25:26.787 に答える
1
>>> import wx
>>> import time
>>> app = wx.App()
>>> b = wx.BusyInfo('Upload Finished!')
>>> time.sleep(5)
>>> del b
>>>
于 2013-10-08T12:35:57.153 に答える