Maya中的按钮反馈颜色python?

时间:2019-03-25 10:55:02

标签: python maya

我是python的初学者。我正在创建一个UI,用于选择场景中的对象。 我希望按钮在从默认灰色单击为白色时更改颜色,并在取消选择后保持白色并重新变为灰色。 谢谢,让我理解起来很简单! 按钮代码:

import maya.cmds as cmds
def MyWindow():    
    #delete existing window
    if cmds.window("GuiWindow", exists = True):
        cmds.deleteUI("GuiWindow")
    #create window
    window = cmds.window("GuiWindow", title = "Object Selecter",\
         w = 400, h = 600, sizeable = False, mxb = False)
    column = cmds.columnLayout(w = 400, h = 600)
    form = cmds.formLayout(w = 400, h = 600)
    #background image
    BGimage = cmds.internalVar(upd = True)+"icons/picker_bg01.jpg"
    cmds.image(w = 400, h = 600, image = BGimage)
    #create button
    object1 = cmds.button(label = "", w = 100, h = 50, \
        bgc = [0.5,0.5,0.5],command=lambda x: cmds.select("object1"))
    # More buttons to be created
    cmds.formLayout(form, e = True,af = (object1,"top",100))
    cmds.formLayout(form, e = True,af = (object1,"left",150))
MyWindow()

cmds.showWindow(window)

1 个答案:

答案 0 :(得分:0)

您始终可以使用参数 edit 设置为true的命令来编辑UI元素。例如

button  = cmds.button(bgc=[.5, .5, .5])
cmds.button(button, edit=True, bgc=[1,1,1])

根据您的情况,您可以创建一个按钮命令并在那里切换颜色。为了简化操作,您甚至可以将 query 参数设置为true来获取当前值。

currentColor = cmds.button(button, query=True, bgc=True)

这样,您可以检查当前颜色,并在需要时切换到另一种颜色。