# Toggle button Label

**URL:** <https://forum.inductiveautomation.com/t/toggle-button-label/67017>\
**Category:** Ignition\
**Tags:** database, python, ignition80, scripting, perspective\
**Created:** [November 29, 2022, 7:28am UTC](https://forum.inductiveautomation.com/t/toggle-button-label/67017 "2022-11-29T07:28:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![saravanan\_Manickam](https://avatars.discourse-cdn.com/v4/letter/s/278dde/32.png) [@saravanan\_Manickam](https://forum.inductiveautomation.com/u/saravanan_Manickam)\
**Post date:** [November 29, 2022, 7:28am UTC](https://forum.inductiveautomation.com/t/toggle-button-label/67017/1 "2022-11-29T07:28:44Z")

</div>

Hi all,

thanks in advance,

I'm facing an issue in the perspective component - toggle button  
 ![tbl](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/9/190b2f4924df9c890bd30d95d9d8a46a924a7a07.png)

here I have script for color & Label. I used the toggle button on the flex repeater  
 ![tglflx](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/d/5da04abd41b6ca93c5e5a5cb2371125dff64ec1d.png)

while saving the data in the database as default it values come as true & false.  
I tried a for loop to convert it but it's not working  
let's consider a parameter as status

Status = ["False","True","True","False"]  
StatusCount =int(len(Status))  
for v in range (StatusCount):  
if Status != "False":  
a = "ok"  
print(a)  
else:  
a = "Not Okay"  
print(a)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [November 29, 2022, 9:24am UTC](https://forum.inductiveautomation.com/t/toggle-button-label/67017/2 "2022-11-29T09:24:23Z")

</div>

A few tips:

1. The toggle is a **switch** - not a button.
2. The toggle has a label property. There's no need for a separate label.
3. Standard windows GUI is that the label remains the same and the switch shows the status. i.e., Every label would say "OK" and the switch show the status. Having "Not OK" gives rise to a double-negative, "The system is not Not OK". Would that mean that it _is_ OK?
4. Switch text would normally be aligned with the switch, not centre-aligned as you have it shown. "OK" (both letters capitalised) is normal.
5. You are using strings. `["False", "True", "True", "False"]`. You should be using booleans. `[False, True, True, False]`. Your code then becomes

```auto
if not Status:

```

1. It appears that you are using a switch as an indicator. Why? It doesn't look right. It looks like more of an application for an indicator.

![LED indicator](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/3/030c9cde80693a5f75659b98bf811d80b450b8dd.png)

Here I've used 32 × 32 labels and created two styles, LEDgreen and LEDred. These have a border set, the corner radius set to 16 and the fill set to theme colors `--success` and `--error` so that they match whatever Perspective theme I'm using.  
However, beware of only using color to indicate status as I have done here as color-blind operators may have a hard time distinguishing the two states.

[https://docs.inductiveautomation.com/display/DOC81/Perspective+Built-In+Themes](https://docs.inductiveautomation.com/display/DOC81/Perspective+Built-In+Themes)

1. When posting code on the forum (or any other) format it using the \</\> button. It preserves indents (essential for Python) and applies syntax highlighting.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [November 29, 2022, 9:30am UTC](https://forum.inductiveautomation.com/t/toggle-button-label/67017/3 "2022-11-29T09:30:43Z")

</div>

1. format your code by using the code button  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/c/0c3eebb0c36cdccfdfe64b8a05fff8b7c155fcdc.png)  
or by wrapping your code in triple backticks:

> ```  
> code  
> ```

Keep in mind that whitespace is significant in python, and you need to use proper code markup in order to keep the indentation when pasting code here.  
Now, in this case, the code is simple enough that we can deduce what it really is, but don't leave formatting to us, that's your job.

1. you need to be more descriptive about what you're trying to do and what is not working.  
For example, you say "while saving the data in the database": What data ? How do you save it ?

2. I suggest you read this: [https://xyproblem.info/](https://xyproblem.info/)

While I have no idea what you're trying to do, I can tell you right now that the script you showed is not going to do what you expect.

```python
Status = ["False","True","True","False"]
StatusCount =int(len(Status))
for v in range (StatusCount):
	if Status != "False":
		a = "ok"
		print(a)
	else:
		a = "Not Okay"
		print(a)

```

- `Status = ["False","True","True","False"]`  
Why are there 4 statuses for a toggle ? Why are you using strings instead of booleans ?
- `StatusCount =int(len(Status))`  
You don't need to cast to int, `len()` already returns one
- `if Status != "False":`  
Status is your list, it can never be equal to a string
- You're checking the same thing for each iteration of your loop. Nothing changes there.

What you probably meant to do was this:

```python
statuses = [False, True, True, False]
for status in statuses:
	if status:
		a = "ok"
	else:
		a = "Not Okay"
	print a

```

But I don't think you really need a script here.  
I think you took a wrong path somewhere and everything became more complicated than it needs to be. That's the xy problem described in the page I linked above.  
Tell us more about what you want to do, not how you're trying to do it.

---

<div class="post-metadata">

**Author:** ![saravanan\_Manickam](https://avatars.discourse-cdn.com/v4/letter/s/278dde/32.png) [@saravanan\_Manickam](https://forum.inductiveautomation.com/u/saravanan_Manickam)\
**Post date:** [November 29, 2022, 10:17am UTC](https://forum.inductiveautomation.com/t/toggle-button-label/67017/4 "2022-11-29T10:17:32Z")

</div>

yeah thanks for your response,

as I already mentioned I'm using a flex repeater in that template i used toggle switch  
for ex: i have 4 instances as i shared the pic  
so, from the instances I received the output has shown below

Status = ["False","True","True","False"]

#here I'm trying to get the length by len() func. & storing it on the variable as StatusCount.

StatusCount =int(len(Status))

#here I'm trying to get the length by len() func. & storing it on the variable as StatusCount. #the value will be 4

#here i'm passing it for the iterarion  
for v in range (StatusCount):  
if Status != "False":  
a = "ok"  
print(a)  
else:  
a = "Not Okay"  
print(a)

* * *

want I'm trying to do means:

I need a input as **ok** or **not okay** anyone  
so by using toggle switch I like to get it .  
Because it's default Boolean (true or false )so I'm trying to change it

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [November 29, 2022, 10:21am UTC](https://forum.inductiveautomation.com/t/toggle-button-label/67017/5 "2022-11-29T10:21:31Z")

</div>

I know full well what each of those lines do. What I'm saying is that putting those lines together doesn't do what you think it does.  
You didn't even mention where that script is, and what triggers it...

But again, I don't think you need that script. I'm 98% sure there's a better solution to your problem...even not knowing what your problem actually is.  
Which is why I asked, and I'm asking again, that you explain what you WANT to do, not HOW you're trying to do it.

edit:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/e/bed5127c92a890dbb933b3cc95088a363b3a9974.png)

No scripts here. No labels either. Only the built-in toggle's properties and one binding.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [November 29, 2022, 10:25am UTC](https://forum.inductiveautomation.com/t/toggle-button-label/67017/6 "2022-11-29T10:25:12Z")

</div>

Please use the \</\> button to format your code properly as requested. We can't tell if you have the indents correct. It's also difficult to read your posts when you don't capitalise sentences correctly. Make it easy for those you are asking to help you. You can use the 🖉 edit link to fix your two previous posts.
