panda3d and tkinter


#1

Hi. I have been struggling to come up with a tkinter Frame that contains a panda3d view. Can anyone please post a small example? Many thanks.

–jeffh


#2

This works for me (tested on Windows and Linux):

from direct.showbase.ShowBase import ShowBase
from panda3d.core import WindowProperties
import Tkinter

# Start ShowBase, but don't open a Panda window yet
base = ShowBase(windowType='none')

# Start Tkinter integration, get the root window handle
base.startTk()

frame = base.tkRoot
frame.update()
id = frame.winfo_id()
width = frame.winfo_width()
height = frame.winfo_height()

props = WindowProperties()
props.setParentWindow(id)
props.setOrigin(0, 0)
props.setSize(width, height)

base.makeDefaultPipe()
base.openDefaultWindow(props=props)

scene = base.loader.loadModel("environment")
scene.reparentTo(base.render)

base.run()

Of course, you’ll want to add code to automatically resize the Panda window when the Tk window is resized, but it gets the point across.


#3

Thanks for this. It helps. But it also crashes on OS X, with a segfault on this line:

base.openDefaultWindow(props=props)

I am experimenting further. FWIW, here is the stack trace:

* thread #1: tid = 0x27af60, 0x00007fff97734d57 libobjc.A.dylib`objc_msgSend + 23, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x8b1110)
  * frame #0: 0x00007fff97734d57 libobjc.A.dylib`objc_msgSend + 23
    frame #1: 0x000000010f5d9f6b libpandagl.dylib`CocoaGraphicsWindow::open_window() + 1963
    frame #2: 0x0000000103a84913 libpanda.1.10.dylib`GraphicsWindow::set_properties_now(WindowProperties&) + 419
    frame #3: 0x000000010f5dc696 libpandagl.dylib`CocoaGraphicsWindow::set_properties_now(WindowProperties&) + 38
    frame #4: 0x0000000103a84589 libpanda.1.10.dylib`GraphicsWindow::process_events() + 121
    frame #5: 0x000000010f5d96da libpandagl.dylib`CocoaGraphicsWindow::process_events() + 26
    frame #6: 0x0000000103a432ed libpanda.1.10.dylib`GraphicsEngine::WindowRenderer::do_windows(GraphicsEngine*, Thread*) + 77
    frame #7: 0x0000000103a3ea99 libpanda.1.10.dylib`GraphicsEngine::open_windows() + 201
    frame #8: 0x0000000103a3de47 libpanda.1.10.dylib`GraphicsEngine::make_output(GraphicsPipe*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<c\
har> > const&, int, FrameBufferProperties const&, WindowProperties const&, int, GraphicsStateGuardian*, GraphicsOutput*) + 2503
    frame #9: 0x0000000102aad4b1 core.so`Dtool_GraphicsEngine_make_output_668(_object*, _object*, _object*) + 769
    frame #10: 0x00000001000b102c Python`PyEval_EvalFrameEx + 15692

#4

According to the Tkinter documentation for winfo_id:

Hmm, I believe we need an NSWindow or NSView pointer. Perhaps Tkinter doesn’t expose this information on Mac OS X? I can’t find anything useful when Googling about it.

It might be possible to render to a texture on Mac, let Panda copy it to RAM, and then render that image in Tkinter in some way or another. But it’d be a significant performance impairment.


split this topic #5

2 posts were split to a new topic: Tkinter error opening directtools