468,284 Members | 1,530 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,284 developers. It's quick & easy.

Embedded window in wxPython app

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
0 1675

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by omission9 | last post: by
3 posts views Thread by Tim Williams | last post: by
1 post views Thread by mitsura | last post: by
6 posts views Thread by zdp | last post: by
reply views Thread by =?ISO-8859-15?Q?J=FCrgen_Kareta?= | last post: by
1 post views Thread by rocksportrocker | last post: by
5 posts views Thread by Jimmy | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.