# Dynamically Changing Font Size using Scripting

**URL:** <https://forum.inductiveautomation.com/t/dynamically-changing-font-size-using-scripting/30887>\
**Category:** Ignition\
**Created:** [December 22, 2019, 5:10am UTC](https://forum.inductiveautomation.com/t/dynamically-changing-font-size-using-scripting/30887 "2019-12-22T05:10:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![qasimahtesham](https://avatars.discourse-cdn.com/v4/letter/q/a5b964/32.png) [@qasimahtesham](https://forum.inductiveautomation.com/u/qasimahtesham)\
**Post date:** [December 22, 2019, 5:10am UTC](https://forum.inductiveautomation.com/t/dynamically-changing-font-size-using-scripting/30887/1 "2019-12-22T05:10:35Z")

</div>

Hi all,

I want to change the font size of text in a template(there will be a button in the template), essentially by binding it to a custom property (Boolean type). Where can I script it? and how?

So in short, its changing the font size of text in a button, via scripting, based on value of the custom property.

Thanks

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [December 22, 2019, 1:05pm UTC](https://forum.inductiveautomation.com/t/dynamically-changing-font-size-using-scripting/30887/2 "2019-12-22T13:05:28Z")

</div>

Maybe this will help you?? It's for a table, but maybe it will carry over. I've never tried to change font during runtime, so don't know one way or another. Font is not bindable, so scripting would be your only choice.

> [@Changing Table Font Size via Script](http://forum.inductiveautomation.com/t/changing-table-font-size-via-script/12094):
>
> All, I am trying to change the font size inside a table based on a script. Is this possible? I get the error that it is a read only attribute, but I thought there was a way to change fonts in a table. Thanks

---

<div class="post-metadata">

**Author:** ![qasimahtesham](https://avatars.discourse-cdn.com/v4/letter/q/a5b964/32.png) [@qasimahtesham](https://forum.inductiveautomation.com/u/qasimahtesham)\
**Post date:** [December 22, 2019, 1:06pm UTC](https://forum.inductiveautomation.com/t/dynamically-changing-font-size-using-scripting/30887/3 "2019-12-22T13:06:48Z")

</div>

I have tried this as a sample, but no luck…

Font=event.source.font  
if (1==1):  
Font=(Dialog,Bold,15)  
else:  
event.source.font=12

Used the avove script, but error is that "Dialog has not been recognised… I guess I am missing some syntax… any suggestions?

---

<div class="post-metadata">

**Author:** ![qasimahtesham](https://avatars.discourse-cdn.com/v4/letter/q/a5b964/32.png) [@qasimahtesham](https://forum.inductiveautomation.com/u/qasimahtesham)\
**Post date:** [December 22, 2019, 1:25pm UTC](https://forum.inductiveautomation.com/t/dynamically-changing-font-size-using-scripting/30887/4 "2019-12-22T13:25:24Z")

</div>

Got this code working, under the button script only

from java.awt import Font  
button = event.source.parent.getComponent(‘Button’)  
button.font = Font(‘Dialog’, 0, 16)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 22, 2019, 2:28pm UTC](https://forum.inductiveautomation.com/t/dynamically-changing-font-size-using-scripting/30887/5 "2019-12-22T14:28:16Z")

</div>

Consider moving your code into a script module, as a function taking a boolean and returning your desired font. Something like this:

```auto
from java.awt import Font
def myDynamicFont(trigger):
    return Font('Dialog', 0, 32 if trigger else 16)

```

Then, on your button’s font property, use a runScript expression binding, like so:

```auto
runScript("project.someScript.myDynamicFont", 0, {Root Container.Button.CustomBoolean})

```

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [December 22, 2019, 3:02pm UTC](https://forum.inductiveautomation.com/t/dynamically-changing-font-size-using-scripting/30887/6 "2019-12-22T15:02:07Z")

</div>

Another way to do this if appropriate, would be to use the style customiser binding to set the font. Create a custom property on the button to use as the driving property

---

<div class="post-metadata">

**Author:** ![qasimahtesham](https://avatars.discourse-cdn.com/v4/letter/q/a5b964/32.png) [@qasimahtesham](https://forum.inductiveautomation.com/u/qasimahtesham)\
**Post date:** [December 22, 2019, 9:48pm UTC](https://forum.inductiveautomation.com/t/dynamically-changing-font-size-using-scripting/30887/7 "2019-12-22T21:48:00Z")

</div>

> [@pturmel](#):
>
> from java.awt import Font def myDynamicFont(trigger): return Font('Dialog', 0, 32 if trigger else 16)

How do I put the script or expression on font property?

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [June 2, 2020, 9:19pm UTC](https://forum.inductiveautomation.com/t/dynamically-changing-font-size-using-scripting/30887/8 "2020-06-02T21:19:50Z")

</div>

Sorry this is so late…  
But you wouldn’t put this script on the property binding itself, you would put this either in a shared script library, as Phil suggested, or you could add it as a custom function on the component itself (shared library is always preferably as it keeps your scripts in one place and organised).  
It’s the runScript command that goes on your font binding
