Starting wxPython after closing Tkinter
We have two applications, one developed with Tkinter interface and the other using wxPython. Both are pretty tricky. When you're done with a Tkinter app, I want the wxPython app to start after a button is selected in the Tkinter app. Is it possible to toggle event loops so that a Tkinter application can easily switch to the wxPython GUI?
In root.destroy
a Tkinter application, the following works:
os.system('python wxGUI.py')
The final program needs to be included in a separate application for multiple operating systems, so this solution will only work if I create a separate py2app
or py2exe
application- specific wxPython and call it that way (which is not ideal).
source to share
Probably the easiest way to achieve this would be to put wxPython on a separate thread and just hide the Tkinter app if you want to call the wxPython app. I was just whipping this example together and it seemed to work for me:
import Tkinter
import wxapp
import wx
from threading import Thread
########################################################################
class WxThread(Thread):
""""""
#----------------------------------------------------------------------
def __init__(self):
""""""
Thread.__init__(self)
self.start()
#----------------------------------------------------------------------
def run(self):
""""""
app = wx.App(False)
frame = wxapp.MyFrame()
app.MainLoop()
########################################################################
class MyApp(object):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
self.root = parent
self.root.title = "Tkinter App"
self.frame = Tkinter.Frame(parent)
self.frame.pack()
btn = Tkinter.Button(self.frame, text="Open wxPython App",
command=self.run_wx)
btn.pack()
def run_wx(self):
self.root.withdraw()
thread = WxThread()
thread.join()
self.root.deiconify()
#----------------------------------------------------------------------
if __name__ == "__main__":
root = Tkinter.Tk()
root.geometry("800x600")
app = MyApp(root)
root.mainloop()
This is what I had in the module wxapp.py
:
import wx
########################################################################
class MyFrame(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, title="wxPython App")
panel = wx.Panel(self)
self.Show()
You may need to experiment a little, as one of the main problems when working with two different GUI tools is that their main loops can interfere with each other. You may have to use a multiprocessing module instead of a streaming module to get around this. I'm not really sure. But that should get you started anyway.
source to share