Quite new with UI and python, I am wondering if it's possible to have a window (in my case with wxPython) which stays alive all the time until we destroy it, to perform many other actions in the meantime. If so, where the main running code should be? Here is an example where it is wrong and doesn't work of course:
from time import sleep
import wx
def do_actions(g):
for i in range(100):
print('Iteration: ', i)
g.SetValue(i)
sleep(1)
class MyFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title)
panel = wx.Panel(self, -1)
self.gauge = wx.Gauge(panel, -1, 50, size=(250, 25))
do_actions(self.gauge)
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, -1, 'wx.Gauge')
frame.Show(True)
app = MyApp(0)
app.MainLoop()
You are probably trying to run, before you've learnt to walk but there's nothing wrong with ambition.
You will need to read up on threading/multiprocessing i.e. running separate processes at the same time.
wxPython has a single main event loop, which is used to monitor all of the the GUI events, so that has to be in control at all times.
We fire up a thread to run each job and the GUI updates are issued as
events.That's probably not a very good explanation so here is a bit of simplistic test code, which illustrates one way of setting this up. The threads only run for a limited time but obviously, you can adjust that.
Hopefully, you can pick the bones out of this enough to get you started.