1
$\begingroup$

Is there a way to format how the value of Float/Int properties are shown in python blender GUI?

enter image description here

Right now it's always the same 'text' + 'value' (+ 'unit' if specified in the prop options).

But what if I want to display

f"text {value} text" 

Or even better, format the value with thousands separators?

f" text {value:,} text"
$\endgroup$

1 Answer 1

2
$\begingroup$

Having a formatted text inside the active part of the UI component is not possible, as far as I know.

What you can do, if it suits the UI you would like to get, is to put a label before and after the component with the value, and display only the value.

row = layout.row()
row.label(text="prefix")
row.separator(factor=1.0) # Optional. just in case you need more space between components
row.prop(propertyOwner, "property", "text="") #will display the property value without the text inside
row.separator(factor=1.0) # Optional. just in case you need more space between components
row.label(text="suffix")

Or, if you don't need the value component to be interactive, you can just draw a simple label, which you will be able to format as any Python string.

str = f"Prefix {propertyOwner.property:,} Suffix"
layout.label(text=str)
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .