An example of Panda3D integration into Tkinter

from direct.showbase.ShowBase import ShowBase
from panda3d.core import WindowProperties
from tkinter import Button, CENTER

class AppTk(ShowBase):

    def __init__(self):
        ShowBase.__init__(self, windowType = 'none')
        base.startTk()

        self.frame = base.tkRoot
        self.frame.geometry("800x600")

        button = Button(self.frame, text = 'Click me !', bd = '5', command = self.test)
        #button.pack(side = 'top') 
        button.place(x = 400, y = 300, anchor = CENTER)

        props = WindowProperties()
        props.set_parent_window(self.frame.winfo_id())
        props.set_origin(0, 0)
        props.set_size(self.frame.winfo_width(), self.frame.winfo_height())

        base.make_default_pipe()
        base.open_default_window(props = props)

        self.frame.bind("<Configure>", self.resize)

        scene = loader.load_model("environment")
        scene.reparent_to(render)

    def test(self):
        print("Hello")

    def resize(self, event):
        props = WindowProperties()
        props.set_origin(0, 0)
        props.set_size(self.frame.winfo_width(), self.frame.winfo_height())
        base.win.request_properties(props)

app = AppTk()
app.run()
3 Likes