将信息从两个文本字段传递到一个函数,在Maya中按一个GUI按钮

时间:2017-10-06 20:08:36

标签: python user-interface maya

在Maya中,使用Python,我想创建一个包含两个文本字段和一个按钮的简单GUI。当按下按钮时,我希望将来自两个文本字段的输入传递给另一个可以操作和操作数据的函数。

示例:

" NAME1" ," name2" 按钮

def edit(name1, name2):
    print "name 1 and name2 = " + name1 + name2 

按下按钮时,名称1和2的信息将传递给该功能,编辑可以使用的位置。

使用Python实现此目的的最简单逻辑是什么?

感谢。

1 个答案:

答案 0 :(得分:0)

您要完成的是按下按钮上的文本字段中的文本值。

示例如何操作:

import maya.cmds as cmds


def createWindow():

    windowID = 'window'


    if cmds.window(windowID, exists = True):
        cmds.deleteUI('window')

    window = cmds.window(windowID)
    cmds.rowColumnLayout()

    cmds.textFieldGrp('textField_A', label = 'Textfield A: ')
    cmds.textFieldGrp('textField_B', label = 'Textfeild B: ' )

    cmds.button(label = 'pass textfield values', command = queryTextField)

    cmds.showWindow( window )

def queryTextField(*args):

    text_A = cmds.textFieldGrp( 'textField_A', query = True, text = True)
    text_B = cmds.textFieldGrp( 'textField_B', query = True, text = True)

   print text_A, text_B

createWindow()

使用以下行查询textfield或textfieldGrp的值。

text_A = cmds.textFieldGrp( 'textField_A', query = True, text = True)