# Shared script to createPopupMenu

**URL:** <https://forum.inductiveautomation.com/t/shared-script-to-createpopupmenu/25546>\
**Category:** Ignition\
**Created:** [June 4, 2019, 5:08pm UTC](https://forum.inductiveautomation.com/t/shared-script-to-createpopupmenu/25546 "2019-06-04T17:08:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dion.botha](https://avatars.discourse-cdn.com/v4/letter/d/46a35a/32.png) [@dion.botha](https://forum.inductiveautomation.com/u/dion.botha)\
**Post date:** [June 4, 2019, 5:08pm UTC](https://forum.inductiveautomation.com/t/shared-script-to-createpopupmenu/25546/1 "2019-06-04T17:08:31Z")

</div>

Hi Guys,

If I do something like this on a components mouseReleased event handler I get what I expect (a popup menu when the component is right clicked):

> def function1():  
> pass
> 
> def rightClickPopup(component):  
> menu = system.gui.createPopupMenu(["Item1"], [function1])  
> menu.show(event)
> 
> rightClickPopup(event.source)

I would like to move this to a shared script named myfuncs:

> def function1():  
> pass
> 
> def rightClickPopup(component):  
> menu = system.gui.createPopupMenu(["Item1"], [function1])  
> menu.show(event)

When a call the function on a mouseReleased event handler on a component like this:

> shared.myfuncs.rightClickPopup(event.source)

I get this error:

> Traceback (most recent call last):
> 
> File "event:mouseReleased", line 1, in
> 
> File "module:shared.myfuncs", line 19, in rightClickPopup
> 
> NameError: global name 'event' is not defined
> 
> Ignition v7.9.9 (b2018081621)  
> Java: Oracle Corporation 1.8.0\_171

Any help would be much appreciated.

---

<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:** [June 5, 2019, 1:01am UTC](https://forum.inductiveautomation.com/t/shared-script-to-createpopupmenu/25546/2 "2019-06-05T01:01:37Z")

</div>

The working examples are taking advantage of jython’s closures – variables in an outer scope referenced by inner scopes are captured at definition time. No event objects or anything else defined in an event or custom method exist in a project script’s scope. You will need to pass the event as an argument to your project script.

---

<div class="post-metadata">

**Author:** ![dion.botha](https://avatars.discourse-cdn.com/v4/letter/d/46a35a/32.png) [@dion.botha](https://forum.inductiveautomation.com/u/dion.botha)\
**Post date:** [June 5, 2019, 3:37pm UTC](https://forum.inductiveautomation.com/t/shared-script-to-createpopupmenu/25546/3 "2019-06-05T15:37:22Z")

</div>

Thanks Phil. Another quick question - can I pass other arguments to the `createPopupMenu` functions?

---

<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 5, 2019, 4:31pm UTC](https://forum.inductiveautomation.com/t/shared-script-to-createpopupmenu/25546/4 "2019-06-05T16:31:06Z")

</div>

No, you cannot. If you’re working with popup menus, [`functools.partial`](https://www.jython.org/docs/library/functools.html) is your friend.

---

<div class="post-metadata">

**Author:** ![dion.botha](https://avatars.discourse-cdn.com/v4/letter/d/46a35a/32.png) [@dion.botha](https://forum.inductiveautomation.com/u/dion.botha)\
**Post date:** [June 5, 2019, 5:45pm UTC](https://forum.inductiveautomation.com/t/shared-script-to-createpopupmenu/25546/5 "2019-06-05T17:45:41Z")

</div>

> [@paul-griffith](#):
>
> If you’re working with popup menus, functools.partial is your friend.

Hi Paul, thanks for the spark! For anyone wanting an example to pass more arguments to `createPopupMenu`:

> from functools import partial
> 
> def function(x, event):  
> print x
> 
> y = 1  
> function\_partial = partial(function, y)  
> menu = system.gui.createPopupMenu(["text"], [function\_partial])  
> menu.show(event)
