2014-01-20 15 views
0

您好我正在學習如何使用Python爲Maya創建自定義UI。我正在努力實現一些我無法做到的事情。我四處搜尋,但找不到我的答案。使用Python的Maya中的簡單自定義UI

import maya.cmds as cmds 

def main(): 

    cmds.window(title='Test Window') 
    cmds.columnLayout() 
    cmds.textFieldGrp('obj1', label='Name', text ="Please enter your name") 
    cmds.textFieldGrp('obj2', label='Address', text = "Please enter your address") 
    cmds.rowLayout(nc=3) 
    cmds.button(label="Lock", width=100, c='disable_texts()') 
    cmds.button(label="Edit", width=100, c='change_texts()') 
    cmds.button(label="Reset", width=100, c='default()') 
    cmds.showWindow() 

def disable_texts(): 
    # disable the text fields 

def change_texts(): 
    # enable the text fields 

def default(): 
    # change the text fields back to default ie like above 
+0

什麼問題? –

+0

由於您沒有在任何地方存儲文本的名稱,因此發佈您將永遠無法更新文本。 'textFieldGroup -e obj1'可能不起作用,因爲你不能確定你還沒有在其他地方找到'obj1'。將命令的結果捕獲到一個變量中並使用它 – theodox

回答

1

這可能會回答你的問題,如果我理解..

cmds.window(title='Test Window') 
cmds.columnLayout() 
cmds.textFieldGrp('obj1', label='Name', text ="Please enter your name") 
cmds.textFieldGrp('obj2', label='Address', text = "Please enter your address") 
cmds.rowLayout(nc=3) 
cmds.button(label="Lock", width=100, c=disable_texts) 
cmds.button(label="Edit", width=100) 
cmds.button(label="Reset", width=100) 
cmds.showWindow() 

def disable_texts(*args): 
    #The e=True is for edit, so I'm 'editing' 'obj1' which is the name of the textFieldGrp 
    cmds.textFieldGrp('obj1', e=True, enable=False) 

作爲一個側面說明,最好是函數對象傳遞給command標誌。如果您不確定原因,請檢查this。至於cmds函數,您應該檢查文檔以查看還有哪些其他命令。

+0

與此處相同的問題 - 直接使用命令而不是字符串作爲回調。 http://stackoverflow.com/questions/21215582/importing-pyc-into-existing-python-script – theodox