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.

Recommended Answers

All 2 Replies

def Step: must by def Step(): and else I don't know :)

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.