Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8546695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:05:38+00:00 2026-06-11T13:05:38+00:00

all i am trying is to is add more items to dictionary and populate

  • 0

all i am trying is to is add more items to dictionary and populate with second button if necessary!!! everything goes fine, on running code from maya script editor by clicking on the blue play button but if i import this script
import funtest
funtest.main()

the window loads up fine but i get error on clicking either of the buttons … So please tell me why is their a difference between executing the code from script editor and the other one by importing..

it shouild be same or if it is what is wrong with my logic ?

import maya.cmds as cmds
dic={}
print("dictionary is empty",dic)
def main():
    inst=btnUI()
    inst.create()


class btnUI(object):
    def __init__(self, winName="winTheWindow"):
        self.winTitle = "The Window"
        self.winName = winName

    def create(self):
        if cmds.window(self.winName, exists=True):
            cmds.deleteUI(self.winName)
        dic['item1']='item1value'
        dic['item2']='item2value'

        cmds.window(self.winName, title=self.winTitle)
        self.mainCol = cmds.columnLayout( adjustableColumn=True )
        self.btnA = cmds.button( label='Press Me - External Func',c='outsideFunc(dic)' )
        self.btnb = cmds.button( label='Populate more items',c='populateDic()' )
        cmds.showWindow( self.winName )
        cmds.window(self.winName, edit=True, widthHeight=[250,75])



def populateDic():
    dic['item3']='item3value'
    dic['item4']='item4value'
    dic['item5']='item5value'

def outsideFunc(dicItems):
    print("Outside function, called from inside a class function")
    print(dicItems)

if __name__ == '__main__':
    main()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T13:05:39+00:00Added an answer on June 11, 2026 at 1:05 pm

    It’s because the resolution of your c arguments to cmds.button() are happening in another namespace. It appears there are several ways to solve it, but I recommend following the more Pythonic way:

    from functools import partial
    self.btnA = cmds.button( label='Press Me - External Func',
                             c=partial(outsideFunc, dic))
    self.btnb = cmds.button( label='Populate more items',c=populateDic)
    

    For button A, I’m using partial to help pass dic to outsideFunc, so that the resultant function produced by partial doesn’t require any arguments (it’s been pre-loaded with the dic argument).

    For button B, this is unnecessary, as it doesn’t take any arguments. So we just give it the name of the function to call. Note the lack of quotes. Python will resolve this in the correct namespace, and will work as expected.

    BTW, this page appears to be helpful and talks about command callbacks: http://www.luma-pictures.com/tools/pymel/docs/1.0/ui.html

    UPDATE: Buttons pass an argument to their callback, so you need to wrap it:

    from functools import partial
    self.btnA = cmds.button( label='Press Me - External Func',
                             c=lambda arg: outsideFunc(dic))
    self.btnb = cmds.button( label='Populate more items',c=lambda arg: populateDic())
    

    This creates a couple of anonymous functions that throw away the argument (since you don’t need it).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to add more values to my row, but all the columns
I trying to select all li elements at second level of the list add
I'm trying to use the PowerShell Add-Member cmd on all the items in an
i'm trying to add readonly to all the inputs and then on the click
I'm trying to add a formatter to my Automapper configuration to style all DateTime?
I'm trying to add a function that will be accessible throughout all parts of
I am trying to add a .html suffix at the end of all strings
I'm trying to add 2 seperate JLabels to 2 seperate JPanels, all within one
I am trying to add edge labels for a graph. It all works well,
I'm no expert in mod_rewrite at all and I'm trying to add a condition

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.