Python Forum
Stop Timer in Different Class
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Stop Timer in Different Class
#1
How can I add code in onStop of LeftPanel to stop the timer created in RightPanel?
Is it possible to stop it from in Frame class? Thanks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import wx
import wx.html2 as webview
 
class LeftPanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent=parent)
        stopBtn = wx.Button(self, label="Stop Timer")
        stopBtn.Bind(wx.EVT_BUTTON, self.onStop)
    def onStop(self,event):
        print('Stop Timer')
class RightPanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent=parent)
        self.current = "http://wxPython.org"
        self.frame = self.GetTopLevelParent()
        self.titleBase = self.frame.GetTitle()
        sizer = wx.BoxSizer(wx.VERTICAL)
        self.wv = webview.WebView.New(self)
        sizer.Add(self.wv, 1, wx.EXPAND)
        self.SetSizer(sizer)
        self.wv.LoadURL(self.current)   
        self.timer = wx.PyTimer(self.Timer1)
        self.timer.Start(3000)
    def Timer1(self):
        print('3-second timer')
class Frame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, title="Stop Timer", size=(500, 300), pos = (500, 300))
        splitter = wx.SplitterWindow(self)
        leftP = LeftPanel(splitter)
        rightP = RightPanel(splitter)
        splitter.SplitVertically(leftP, rightP)
        splitter.SetMinimumPaneSize(200)
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(splitter, 1, wx.EXPAND)
        self.SetSizer(sizer)
if __name__ == "__main__":
    app = wx.App()
    win = Frame()
    win.CreateStatusBar()
    win.Show()
    app.MainLoop()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Stop Watch star/stop problem macellan85 1 3,241 Jun-12-2019, 06:04 PM
Last Post: woooee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020