Python: display result Table after calculation

Is there a way to display the result table by default?
I have created it but it is hidden by default, I must go to Data module and open the eye manually. I want to do this in my python script. The table shall be displayed in the tables widget.

If I try to force by widget logic this happens

>>> slicer.qMRMLTableWidget().setMRMLTableViewNode(tablenode)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
TypeError: method requires a vtkMRMLTableViewNode, a vtkMRMLTableNode was provided.

And there is nothing like setMRMLTableNode.

I also tried the following:

>>> tableview = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLTableViewNode')
>>> tableview.SetTableNodeID(tablenode.GetID())
>>> slicer.qMRMLTableWidget().setMRMLTableViewNode(tableview)
>>> slicer.mrmlScene.AddNode(tableview)

but still nothing

This example shos how to do this with plots ( but I want to do it with tables
I tried the equivalent procedure but it does not work: The tableWidget.mrmlTableViewNode() method does not exists. It has however the tableWidget.setMRMLTableViewNode(), but no way to get it.
What am I missing here?

This was harder than I thought, but finally came to a working code:

    # Creation of your table
    resultsTableNode = (...)
    # Create the layout manager to show the table
    layoutManager =
    layoutTable = slicer.modules.tables.logic().GetLayoutWithTable(layoutManager.layout)
    # Create the table widget and assign the table
    tablewidget = layoutManager.tableWidget(0)
    tableview = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLTableViewNode')

Hmm, If I call this repetitively with another table it does not work, it creates more tableviews but the tablewidget is not refreshed. So I keep researching

Deep, very deep in the Slicer source code, there is the SegmentStatistic module which contains the answer, it is obscured

def showTable(self, table):
    Switch to a layout where tables are visible and show the selected table
    currentLayout =
    layoutWithTable = slicer.modules.tables.logic().GetLayoutWithTable(currentLayout)

You can also use slicer.modules.plots.logic().ShowChartInLayout(plotChartNode) as shown in this example in script repository:

What do you mean? Is this also working with table nodes?

You are right, it’s only for charts, the same kind of “show” utility function could be added to tables module logic.