Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 每次在文本滚动列表中更改选择时更新选项菜单项_Python_Maya - Fatal编程技术网

Python 每次在文本滚动列表中更改选择时更新选项菜单项

Python 每次在文本滚动列表中更改选择时更新选项菜单项,python,maya,Python,Maya,我有一个既有文本滚动列表又有选项菜单的窗口。每当文本列表中的选项发生更改时,我希望刷新选项菜单项 我真的不确定从这个开始 我正在使用常规的Maya Python。您必须使用一个功能来填充文本滚动并将其附加到on selectCommand标志 您可能必须在函数中使用部分传递textscroll名称作为arg 希望能有所帮助。基本技巧就是确保更新函数的定义方式能够让它知道optionMenu和textScrollList的名称,这样它就可以编辑它们了。简单的方法是在声明这两个项并将其存储在变量中之

我有一个既有文本滚动列表又有选项菜单的窗口。每当文本列表中的选项发生更改时,我希望刷新选项菜单项

我真的不确定从这个开始


我正在使用常规的Maya Python。

您必须使用一个功能来填充文本滚动并将其附加到on selectCommand标志

您可能必须在函数中使用部分传递textscroll名称作为arg


希望能有所帮助。

基本技巧就是确保更新函数的定义方式能够让它知道optionMenu和textScrollList的名称,这样它就可以编辑它们了。简单的方法是在声明这两个项并将其存储在变量中之后定义回调—只要这都在一个范围内—python将通过闭包自动插入所需的值—这比手动执行要优雅得多

这里有一个非常简单的例子

w = cmds.window()
c = cmds.columnLayout()
sl = cmds.textScrollList( append = ['a', 'b', 'c'])
op = cmds.optionMenu(label = 'test')
cmds.menuItem('created by default')


# the callback is defined after the ui so it knows the values of 'sl' and 'op'

def edit_options():
    # gets a list of selected items from the textScroll
    selected = cmds.textScrollList(sl,q=True, si=True)

    # loop through existing menus in the optionMenu and destroy them
    for item in cmds.optionMenu(op, q=True, ill=True) or []:
        cmds.deleteUI(item)

    # add a new entry for every item in the selection
    for item in selected:
        cmds.menuItem(label = item, parent = op)

    # and something not dependent on the selection too
    cmds.menuItem(label = 'something else', parent = op)

# hook the function up - it will remember the control names for you
cmds.textScrollList(sl, e=True, sc = edit_options)

cmds.showWindow(w)

更多背景信息:

您能提供一些代码吗?