wxPython Or Tkinter (or both? w/ threads?)

Chad Franklin Netzer cnetzer at Stanford.EDU
Thu Aug 16 23:45:48 CEST 2001


I have an app that uses Tkinter.  It plots data and
allows for interactive modification of that data.
However, the Tkinter Canvas is so slow that I've also
had to support PyOpenGL rendering (which is a pain
because Togl has "issues").

One thought I've had is to switch completely to another
GUI toolkit, such as wxPython, or PyGtk.  However, I
thought it might be possible to just support the
Canvases (or direct drawing) of another GUI, while
still using Tkinter for the remainder of the interface.

So, can anyone tell me how this might be accomplished.
I made a test program to demonstrate that I could run
both the Tkinter and wxPython mainloops in separate
threads.  What are the limits of this approach (I
assume their will be issues with event handling)?  Is
it really just this simple?


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

import threading
import Tkinter
Tk = Tkinter

from wxPython.wx import *

def tk_button_press():
    print "Tkinter button pressed"
    return

def wx_button_press(event):
    print "wxPython button pressed"
    return

class MyWxApp(wxApp):
    def OnInit(self):
        frame = wxFrame(NULL, -1, "Hello from wxPython")
        frame.Show(true)

        wx_button = wxButton(frame, 10, "Hello", wxPoint(20, 20))
        EVT_BUTTON(frame, 10, wx_button_press)

        self.SetTopWindow(frame)
        return true


if __name__ == '__main__':

    tk_root = Tk.Button(text='Tkinter', command=tk_button_press)
    tk_root.pack()

    wx_root = MyWxApp(0)

    t = threading.Thread( target=wx_root.MainLoop )
    t.start()

    tk_root.mainloop()
    t.join()
-- 
Chad Netzer
chad.netzer at stanfordalumni.org




More information about the Python-list mailing list