Display Text in Slice view

I’m would like to display unique text in the slice view for each slice.

I’m currently trying to use the python script to display text in slice view:

# Set text to "Something"
# Set color to red
# Update the view

However nothing shows up, do I have to enable something?

Another question I have is would this script display the same text for all the slices? So if I scroll through the slices it would be the same text? How can I display unique text for each slice?

The code above works well for me - displays text in 3D view as expected.

To display text in slice views, replace the first line by this line:

view = slicer.app.layoutManager().sliceWidget("Red").sliceView()

You may consider hiding slice view annotations, to prevent them from overwriting the text you place there. See example.

thank you very much! it displays for me now

Sorry one more question I have is, can I change the font size of the text? like make it bigger?

Yes, sure, see how the text is scaled by DataProbe:

thank you very much!!