By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,907 Members | 1,932 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,907 IT Pros & Developers. It's quick & easy.

How to close app after x seconds.

P: n/a
Hi

I have small app that I want to close tself after x seconds. Basically
start show some message and close.

I come up with something like this but it does not work. Can anyone help
me with it?

#!/usr/bin/env python

import wx
import time

class MyFrame(wx.Frame):
def __init__(self, title, pos, size):
wx.Frame.__init__(self, None, -1, title, pos, size)
self.CreateStatusBar()
self.SetStatusText("Some message here")

class MyApp(wx.App):
def OnInit(self):

self.frame = MyFrame('TITLE', (100, 100), (400,100))
self.frame.Show()

self.SetTopWindow(self.frame)
self.ID_Timer = wx.NewEventType()
self.timer = wx.Timer(self, self.ID_Timer)
self.timer.Start(5000, False)
self.Bind(wx.EVT_TIMER, self.appclose, self.timer)
# wx.EVT_TIMER(self, self.ID_Timer, self.appclose)
return True

def appclose(self, evt):
self.frame.Destroy()

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

Ralph
http://TheOrangeIT.org
Jun 27 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
CM
On Jun 8, 8:51 pm, ralphz <ralphza...@sbcglobal.netwrote:
Hi

I have small app that I want to close tself after x seconds. Basically
start show some message and close.

I come up with something like this but it does not work. Can anyone help
me with it?

#!/usr/bin/env python

import wx
import time

class MyFrame(wx.Frame):
def __init__(self, title, pos, size):
wx.Frame.__init__(self, None, -1, title, pos, size)
self.CreateStatusBar()
self.SetStatusText("Some message here")

class MyApp(wx.App):
def OnInit(self):

self.frame = MyFrame('TITLE', (100, 100), (400,100))
self.frame.Show()

self.SetTopWindow(self.frame)
self.ID_Timer = wx.NewEventType()
self.timer = wx.Timer(self, self.ID_Timer)
self.timer.Start(5000, False)
self.Bind(wx.EVT_TIMER, self.appclose, self.timer)
# wx.EVT_TIMER(self, self.ID_Timer, self.appclose)
return True

def appclose(self, evt):
self.frame.Destroy()

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

Ralphhttp://TheOrangeIT.org
It works for me just fine. How is it not working for you?

By the way, showing your message in the statusbar is not a
good display method--it's small and it is only seen in conjunction
with a frame above it that is doing something. You could just put
the message as staticText.
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.