Running wxPython after closing Tkinter Running wxPython after closing Tkinter tkinter tkinter

Running wxPython after closing Tkinter


Probably the simplest way to accomplish this would be to put wxPython into a separate thread and just hide the Tkinter app when you want to call the wxPython app. I just whipped this example together and it seemed to work for me:

import Tkinterimport wxappimport wxfrom 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 wxapp.py module:

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 might have to experiment a bit as one of the main issues with running two different GUI toolkits is that their main loops can interfere with each other. You may have to use the multiprocessing module instead of the threading module to get around that. I'm not really sure. But this should get you started anyway.