How to close app after x seconds.

R

ralphz

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
 
C

CM

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top