Why fontSize of vtkTextActor() not working as setup-values (via Python)?

Operating system: Windows
Slicer version: 4.11.0-2019-06-23 r28335
Expected behavior: font-size adjustment
Actual behavior: X

Hi All, I tried to use vtk.vtkTextActor() to set up a text-info in a window as in the following code, but The fontsize did not change as expected, instead it showed as the original size (12). Why? Thanks a lot in advance!

lm = slicer.app.layoutManager()
layout = lm 
import os 
redRenderer = layout.sliceWidget('Red').sliceView().renderWindow().GetRenderers().GetFirstRenderer()
redRenderWindow =  redRenderer.GetRenderWindow()
vn_red = slicer.mrmlScene.GetNodeByID('vtkMRMLSliceNodeRed')
slicer.app.layoutManager().layout = 6
sliceLogic = lm.sliceWidget(vn_red.GetLayoutName()).sliceLogic()
originalSliceOffset = sliceLogic.GetSliceOffset()
interactor =  redRenderWindow.GetInteractor()
text = vtk.vtkTextActor()
text.SetInput('Testing Info Text')
textProperty = text.GetTextProperty()
print('Before changing = ', textProperty.GetFontSize())
fontsize_text = 60
print('After Changing = ', textProperty.GetFontSize())
textProperty.SetColor(1, 1, 0)
text_representation = vtk.vtkTextRepresentation()
text_representation.GetPositionCoordinate().SetValue( 0.025, 0.92850     )
text_widget = vtk.vtkTextWidget(); 
text_widget.EnabledOn(); text_widget.On()


If you put your text actor into a vtkTextWidget then the text widget will take care of the font size. You can make the text bigger by clicking the edge or corner of the textbox and drag it to make it larger.

Thanks, Andras.
I know that dragging works there. What I would expect is that I would like to control it by user-GUI to adjust/input a number as needed.

The text actor does now know that it is embedded in a text widget, so if you want to modify the text size then you have to do it in the widget. Maybe simply calling ResizableOff on the widget is sufficient, but if not then you need to check out the implementation and maybe you’ll have to add a two-way synchronization mechanism between the widget and the actor.

Why do you need a custom widget? You can use markups fiducials to display labels in slice and 3D views.