# Script work in script console but not work from from button perspective

**URL:** <https://forum.inductiveautomation.com/t/script-work-in-script-console-but-not-work-from-from-button-perspective/91497>\
**Category:** Ignition\
**Tags:** ignition81, perspective, scripting\
**Created:** [June 6, 2024, 4:46pm UTC](https://forum.inductiveautomation.com/t/script-work-in-script-console-but-not-work-from-from-button-perspective/91497 "2024-06-06T16:46:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MAYUR\_GHUGE](https://avatars.discourse-cdn.com/v4/letter/m/2acd7d/32.png) [@MAYUR\_GHUGE](https://forum.inductiveautomation.com/u/MAYUR_GHUGE)\
**Post date:** [June 6, 2024, 4:46pm UTC](https://forum.inductiveautomation.com/t/script-work-in-script-console-but-not-work-from-from-button-perspective/91497/1 "2024-06-06T16:46:22Z")

</div>

i am using following code in script console, script work in console fine, but not work  
from button (basically its user Guide for operation)  
'''

# Import necessary modules

from java.awt import Color  
from javax.swing import DefaultListModel, Timer  
from javax.swing import JList  
from javax.swing import JScrollPane  
from javax.swing import JFrame  
from java.awt import BorderLayout

# Create a list model to store messages

messageListModel = DefaultListModel()

# Function to add a message to the list

def addMessage(message):  
messageListModel.addElement(message)

# Function to clear all messages from the list

def clearMessages():  
messageListModel.clear()

# Create a JFrame to display the list

frame = JFrame("UGU")  
frame.setSize(400, 300)  
#frame.setDefaultCloseOperation(JFrame.EXIT\_ON\_CLOSE)

# Create a JList with the message list model

messageList = JList(messageListModel)

# Set some visual properties for the list

messageList.setBackground(Color.WHITE)  
messageList.setForeground(Color.BLACK)

# Create a scroll pane to hold the list

scrollPane = JScrollPane(messageList)

# Add the scroll pane to the frame

frame.getContentPane().add(scrollPane, BorderLayout.CENTER)

# Function to display the frame

def showFrame():  
frame.setVisible(True)

# Function to close the frame after 3 seconds

def closeFrame():  
frame.dispose()

value1=True  
value2=True  
value3=False

# Example usage:

if value1:  
addMessage("Error: Pump 1 failure")  
if value2:  
addMessage("Warning: Tank level low")  
if value3:  
addMessage("Error: Pump 2 failure")

# Call the function to display the frame

showFrame()

# Schedule the frame to close after 3 seconds

timer = Timer(2000, lambda e: closeFrame())  
timer.setRepeats(False)  
timer.start()  
'''

---

<div class="post-metadata">

**Author:** ![YF129701](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yf129701/32/60498_2.png) [@YF129701](https://forum.inductiveautomation.com/u/YF129701)\
**Post date:** [June 6, 2024, 4:52pm UTC](https://forum.inductiveautomation.com/t/script-work-in-script-console-but-not-work-from-from-button-perspective/91497/2 "2024-06-06T16:52:38Z")

</div>

Can you post your code formatted without the comments you added?

Just post exactly what's in your script console. Use something like  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/7/8795f07a641828b4442e4aeccc03fc58322737ce.png)

and code will show up formatted, like this:

```python
def sampleFunction(prob):
    print "hello"

```

---

<div class="post-metadata">

**Author:** ![YF129701](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yf129701/32/60498_2.png) [@YF129701](https://forum.inductiveautomation.com/u/YF129701)\
**Post date:** [June 6, 2024, 4:55pm UTC](https://forum.inductiveautomation.com/t/script-work-in-script-console-but-not-work-from-from-button-perspective/91497/3 "2024-06-06T16:55:16Z")

</div>

Also, I don't really understand what you're trying to do... You tagged the post as Perspective, but you're using Java Swing? For what reason?

All the scripting you write on Perspective buttons or other components will run on the Ignition server, so I'm not sure what you're expecting to happen.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 6, 2024, 5:01pm UTC](https://forum.inductiveautomation.com/t/script-work-in-script-console-but-not-work-from-from-button-perspective/91497/4 "2024-06-06T17:01:55Z")

</div>

ChatGPT (or whatever LLM you're using) doesn't understand Ignition well enough to be helpful. Don't bother asking it Ignition related questions.

You may get a volunteer well motivated enough to untangle your intentions from what you've posted, but what you've done here has _nothing_ to do with Ignition's provided visualization systems (Vision or Perspective).

---

<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:** [June 6, 2024, 5:35pm UTC](https://forum.inductiveautomation.com/t/script-work-in-script-console-but-not-work-from-from-button-perspective/91497/5 "2024-06-06T17:35:52Z")

</div>

Please see [Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831). Then hit the pencil icon under your post to edit and fix it. Thanks.
