我所要做的就是向字典中添加更多项目,并在必要时使用第二个按钮填充!!!一切顺利,通过单击蓝色播放按钮从 Maya 脚本编辑器运行代码,但如果我导入此脚本 import funtest funtest.main()
窗口加载正常,但单击任一按钮时出现错误...所以请告诉我为什么它们在从脚本编辑器执行代码和通过导入执行另一个代码之间有区别..
它应该是一样的,或者我的逻辑有什么问题?
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()