OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to visualize 3D model from vispy on tkinter canvas?

  • Thread starter Thread starter naterkrth
  • Start date Start date
N

naterkrth

Guest
I am using Vispy to create 3D visualization. I use Tkinter for my GUI. Are there any way to replace self.panel1 with Vispy Canvas? or embeded Vispy Canvas into self.panel1 (Tkinter canvas). In this code, the output give me 2 seperated windows.

Code:
def init_panels(self):
    self.panel1 = self.create_panel("3D", "white", "white")
    self.panel2 = self.create_panel("XY", "magenta", "yellow")
    self.panel3 = self.create_panel("YZ", "blue", "magenta")
    self.panel4 = self.create_panel("XZ", "blue", "yellow")

    self.panel1.grid(row=0, column=0, sticky="nsew", padx=1, pady=1)
    self.panel2.grid(row=0, column=1, sticky="nsew", padx=1, pady=1)
    self.panel3.grid(row=1, column=0, sticky="nsew", padx=1, pady=1)
    self.panel4.grid(row=1, column=1, sticky="nsew", padx=1, pady=1)

    self.content_frame.grid_columnconfigure(0, weight=1, minsize=512)
    self.content_frame.grid_columnconfigure(1, weight=1, minsize=512)
    self.content_frame.grid_rowconfigure(0, weight=1, minsize=512)
    self.content_frame.grid_rowconfigure(1, weight=1, minsize=512)

    self.panels.extend([self.panel1, self.panel2, self.panel3, self.panel4])

    # Initial axes
    self.update_panel_images()

def create_panel(self, label_text, x_color, y_color):
    panel = Frame(self.content_frame, bg="black", width=512, height=512)
    panel.pack_propagate(False)  # Prevent the panel from resizing to fit its contents
    panel.canvas = Canvas(panel, bg="black")
    panel.canvas.pack(fill="both", expand=True, anchor="center")
    panel.bind("<Configure>", self.on_panel_resize)
    
    return panel

def visualize_vispy(self, volume3d):
    
    canvas = scene.SceneCanvas(keys='interactive', show=True)
    view = canvas.central_widget.add_view()
    
    volume = scene.visuals.Volume(volume3d, parent=view.scene, threshold=0.225)
    
    view.camera = scene.cameras.TurntableCamera(parent=view.scene, fov=60)
    view.camera.set_range()
    
    canvas.native.master = self.panel1
    canvas.native.pack(side=TOP, fill=BOTH, expand=1)

In this code, I got this error. AttributeError: 'CanvasBackendDesktop' object has no attribute 'pack'

I expect to visualize 3D model from Vispy in self.panel1 Is it possible?
<p>I am using Vispy to create 3D visualization. I use Tkinter for my GUI.
Are there any way to replace self.panel1 with Vispy Canvas? or embeded Vispy Canvas into self.panel1 (Tkinter canvas). In this code, the output give me 2 seperated windows.</p>
<pre><code>def init_panels(self):
self.panel1 = self.create_panel("3D", "white", "white")
self.panel2 = self.create_panel("XY", "magenta", "yellow")
self.panel3 = self.create_panel("YZ", "blue", "magenta")
self.panel4 = self.create_panel("XZ", "blue", "yellow")

self.panel1.grid(row=0, column=0, sticky="nsew", padx=1, pady=1)
self.panel2.grid(row=0, column=1, sticky="nsew", padx=1, pady=1)
self.panel3.grid(row=1, column=0, sticky="nsew", padx=1, pady=1)
self.panel4.grid(row=1, column=1, sticky="nsew", padx=1, pady=1)

self.content_frame.grid_columnconfigure(0, weight=1, minsize=512)
self.content_frame.grid_columnconfigure(1, weight=1, minsize=512)
self.content_frame.grid_rowconfigure(0, weight=1, minsize=512)
self.content_frame.grid_rowconfigure(1, weight=1, minsize=512)

self.panels.extend([self.panel1, self.panel2, self.panel3, self.panel4])

# Initial axes
self.update_panel_images()

def create_panel(self, label_text, x_color, y_color):
panel = Frame(self.content_frame, bg="black", width=512, height=512)
panel.pack_propagate(False) # Prevent the panel from resizing to fit its contents
panel.canvas = Canvas(panel, bg="black")
panel.canvas.pack(fill="both", expand=True, anchor="center")
panel.bind("<Configure>", self.on_panel_resize)

return panel

def visualize_vispy(self, volume3d):

canvas = scene.SceneCanvas(keys='interactive', show=True)
view = canvas.central_widget.add_view()

volume = scene.visuals.Volume(volume3d, parent=view.scene, threshold=0.225)

view.camera = scene.cameras.TurntableCamera(parent=view.scene, fov=60)
view.camera.set_range()

canvas.native.master = self.panel1
canvas.native.pack(side=TOP, fill=BOTH, expand=1)
</code></pre>
<p>In this code, I got this error.
AttributeError: 'CanvasBackendDesktop' object has no attribute 'pack'</p>
<p>I expect to visualize 3D model from Vispy in self.panel1
Is it possible?</p>
 

Latest posts

Top