By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,723 Members | 1,270 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,723 IT Pros & Developers. It's quick & easy.

Embedded window in wxPython app

P: n/a
I've been experimenting with passing a window handle from a wxPython app to
a Tkinter app. The Tkinter app should embed a Toplevel window containing a
Canvas widget in the wxPython app's Frame (see example below).

Both apps run, but the Tkinter app's output doesn't appear.

Can anyone see why this isn't working?

Using wxPython-2.5.1/Python 2.3.3/Win98 and Win2000.

regards
Richard

----------------------------

#!/usr/bin/env python
# generated by wxGlade 0.3.3 on Thu Jun 03 14:36:32 2004

import wx
import os
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: MyFrame.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)

self.__set_properties()
self.__do_layout()
# end wxGlade
def __set_properties(self):
# begin wxGlade: MyFrame.__set_properties
self.SetTitle("frame_1")
# end wxGlade

def __do_layout(self):
# begin wxGlade: MyFrame.__do_layout
self.Layout()
# end wxGlade
def StartSlave(self):
# Get the window id
window_id = str(self.GetHandle())
print 'In wx_app window_id =', window_id

script = 'tk_slave.py'
cmd = r"C:\python23\python.exe"
args = [script, script, window_id]
os.spawnv(os.P_NOWAIT, cmd, args)

#self.Refresh()
# end of class MyFrame
class MyApp(wx.App):
def OnInit(self):
wx.InitAllImageHandlers()
frame_1 = MyFrame(None, -1, "")
self.SetTopWindow(frame_1)
frame_1.Show(1)
frame_1.StartSlave()
return 1

# end of class MyApp

if __name__ == "__main__":
app = MyApp(0)
app.MainLoop()

----------------------------

#!/usr/bin/env python
# Module: tk_slave.py

import sys
import Tkinter
class EmbeddedTk:
"""Create Embedded Tk app inside a wxPython app """

def __init__(self, window_id):
print 'Received window id =', window_id

self.window_id = window_id
self.root = Tkinter.Tk()
self.root.withdraw()

toplevel = Tkinter.Toplevel(use=self.window_id)
#toplevel = Tkinter.Toplevel(self.root)

self.c = Tkinter.Canvas(toplevel, width=250, height=250,
bg='white', bd=0)
self.c.pack()
self.c.create_rectangle(20,20,230,230)
self.root.mainloop()
if __name__ == '__main__':

if len(sys.argv) != 2:
sys.exit('Usage: python tk_slave.py window_id\n')
window_id = sys.argv[1]
EmbeddedTk(window_id)
Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.