Suppose I have a large program which takes a while to complete, when the program starts, I found some parameter is not correctly set, so I want to stop it. Instead of terminate the program completely, I want the running calculation to stop but the wx.Frame still shown. Is it possible? Below is the sample code:
import wx
import time
class Test(wx.Frame):
def __init__(self, title):
super().__init__(None, title=title)
self.panel = wx.Panel(self)
self.initUI()
self.Centre()
def initUI(self):
vbox = wx.BoxSizer(wx.VERTICAL)
button1 = wx.Button(self.panel, label="START Calculation")
button1.Bind(wx.EVT_BUTTON, self.start_test)
button2 = wx.Button(self.panel, label="STOP Calculation")
button2.Bind(wx.EVT_BUTTON, self.stop_test)
vbox.Add(button1, 0, wx.ALL, 5)
vbox.Add(button2, 0, wx.ALL, 5)
self.panel.SetSizer(vbox)
def start_test(self, e):
for i in range(20000):
print("Program is running...")
time.sleep(5)
def stop_test(self, e):
print("How do I stop the test when click this button?")
if __name__ == '__main__':
app = wx.App()
Test("A large program").Show()
app.MainLoop()
As shown in the program, when I click start button, the program runs. I hope I can stop the program but still keep the app window. For now, when I click the start button, the stop button is not even clickable. Is it possible to achieve the goal I want?