Built vtk with tkinter on MacOS (Macbook Air), Render Window breaks down on Macbook Pro

Hello.
I built VTK 9.0.1 with tkinter Python 3.8.5 for Macos (Intel, Big Sur) on a Macbook Air, and built an app that visualizes dicom images. App works perfectly fine on Macbook Air. Tested it on multiple devices. However, on testing the app on Macbook Pro, the render window breaks down. It minimizes, leaves the set grid position, and overlaps other widgets on the tkinter window.

What could cause this difference in behaviour?
I assumed building on macos environment would work across all mac devices (air, pro, mini, imac).

Alternatively, are there any builds of VTK available anywhere with tkinter included? That would work consistently, like the ones on pypi, but with VTK included.

My guess is that it is GPU driver related. @ken-martin?

Sounds like a tkinter version issue maybe? I would not expect a GPU driver issue to cause window sizing, positioning issues.

@ken-martin Could macbook pro and air on the same version of MacOS (Big Sur) have different tkinter versions? (I’m new to building apps in this environment)
The frozen app is built with tk8.6, that ships with python 3.8.

The render window itself still works, displays images, can be interacted with, on macbook pro. Just totally breaks down in terms of position and size.

I doubt that vtkTkRenderWidget will work on Retina displays. On my part, I’ve used tkinter on Windows and Linux recently, but I haven’t used tkinter on macOS for a couple years at least.

Fixing vtkTkRenderWidget for retina might be easy or might be hard.

I built VTK with Tkinter on Windows and Linux. The app works well on both platforms on multiple devices. It is only on MacOS that I have seen this issue.

@dgobbi What solution would you suggest? As the macbook pros I tested on definitely had retina displays.

There are a few things you can investigate:

  • Try an external monitor (or even a TV) on the MacBook to check that the Retina display is the only issue.
  • Check to see if there is anything in Tk itself to accommodate Retina displays.
  • Try editing vtkTkRenderWidget.cxx (and possibly vtkCocoaTkUtilities.mm) to modify the size and position as needed for Retina.

VTK has been made to support Retina through Qt and Cocoa, so Tk should theoretically be possible too.

A quick follow-up. I tried the old squadViewer.py example on Retina and the problem really does appear to be a scaling/positioning issue and nothing more:

This is with tcl/tk 8.6.8 and Python 3.7.7.

Alright. Thanks for the confirmation!
Will work on editing the size and position for retina.

Hi,
Following the info you mentioned earlier, that ‘VTK has been made to support Retina through Qt and Cocoa…’

I decided to make a go of building the app on qt and have been largely successful.
However, I have noticed an offset between the mouse-click position on screen, and the relative position on the render window. See the screenshot below, where to get the handle of the Box Widget, I would have to click at the cursor position.

The render window is built with PySide following your guide here:

Do you have any idea what causes the offset @dgobbi ? And how to fix it.

I also noticed the offset when adding TextActors to the screen, and have to compensate when setting DisplayPosition.

The QVTKRenderWindowInteractor in that example is quite old, try using the current one from the VTK master branch. I’m not sure if the retina support is complete, but the code is straightforward and should be easy to modify.

Also please note that QVTKRenderWindowInteractor.py is completely different from the QVTKOpenGLNativeWidget.cxx that is used by ParaView and other C++ applications. VTK’s C++-Qt code is tested on a regular basis by Kitware, but QVTKRenderWindowInteractor.py is a community-supported class, so it’s really only tested and patched by users such as yourself.

Thanks a lot. Using the QVTKRenderWindowInteractor from the VTK master branch fixed the problem!