Just an experiment to explore the use of wxPython buttons to start and stop a process ...
# explore WxPython buttons to start and stop a process
# set flag to 'stop' to allow exit
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, mytitle):
wx.Frame.__init__(self, parent, -1, mytitle, size=(300, 200))
self.SetBackgroundColour("yellow")
self.start_btn = wx.Button(self, -1, label='Start')
self.start_btn.Bind(wx.EVT_BUTTON, self.start_btnClick)
self.stop_btn = wx.Button(self, -1, label='Stop')
self.stop_btn.Bind(wx.EVT_BUTTON, self.stop_btnClick)
self.label = wx.StaticText(self, -1, "-------")
# layout the widgets in a vertical order
sizer_v = wx.BoxSizer(wx.VERTICAL)
# Add(widget, proportion, flag, border)
sizer_v.Add(self.start_btn, 0, flag=wx.ALL, border=10)
sizer_v.Add(self.stop_btn, 0, flag=wx.ALL, border=10)
sizer_v.Add(self.label, 0, flag=wx.ALL, border=10)
self.SetSizer(sizer_v)
self.char = '>'
def start_btnClick(self, event):
self.flag = 'start'
self.processing()
def stop_btnClick(self, event):
self.flag = 'stop'
self.processing()
def processing(self):
self.SetTitle(self.flag)
while True:
if self.flag == 'stop':
break
if self.flag == 'start':
self.label.SetLabel(self.char)
# needed to keep other processes going
wx.GetApp().Yield()
wx.Sleep(1)
self.char += '>'
app = wx.App(0)
MyFrame(None, 'start and stop').Show()
app.MainLoop()