0

Hello all,
Actually i need to close a dialog automatically after 5-6 seconds.
For it what should i do,please help me.I am using wxTimer

        self.MB = wx.Dialog(self,-1,"hello",pos=(-1,-1),size=(200,100),style=wx.NO_3D)
        self.SB = wx.StaticBox(self.MB,"Here description of atelier will come")
        self.MB.Show(True)
        self.timer = wx.Timer(5,self.Step(self))
        self.timer.Start()


def Step:
       if self.timer.IsRunning():
            print ""
       else:
            self.MB.Close(True)

Is this code is not correct or what?
Please help me.

Edited by happygeek: fixed formatting

3
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by jrcagle
0

So it turns out that Timer objects don't receive normal callback functions, but event handler objects. If you don't feel like making one, then you can subclass the Timer and make your own Notify() method for it.

That's what I did here:

import wx

class MyTimer(wx.Timer):

    def Notify(self):
        m.frame.MB.Close(True)  # << No need to check for self.IsRunning!
        self.Stop()
        
class MyFrame(wx.Frame):

    def __init__(self, parent=None, id=-1, size=(300,400)):
        wx.Frame.__init__(self, parent=parent, id=id, size=size)

        self.MB = wx.Dialog(self,-1,"hello",pos=(-1,-1),size=(200,100),style=wx.NO_3D)
        self.SB = wx.StaticBox(parent=self.MB,label="Here description of atelier will come") ## << these are not positional parameters; they need the keywords 'parent' and 'label'
        self.MB.Show(True)
        self.timer = MyTimer() # << Timer.__init__() does not accept a time value.
        self.timer.Start(5000)  # << times measured in msec, not sec.


m = wx.App()
m.frame = MyFrame()
m.MainLoop()

Jeff

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.