首页 > 解决方案 > 在 Maya Python 中刷新选择选项卡

问题描述

我有一个tablayoutMaya Python。每次浏览选项卡时,我都会尝试显示一个随机数。在下面我没有得到如何刷新选项卡

import maya.cmds as cmds
cmds.window( widthHeight=(200, 150) )
form = cmds.formLayout()
tabs = cmds.tabLayout(innerMarginWidth=5, innerMarginHeight=5)
cmds.formLayout( form, edit=True, attachForm=((tabs, 'top', 0), (tabs, 'left', 0), (tabs, 'bottom', 0), (tabs, 'right', 0)) )

child1 = cmds.rowColumnLayout(numberOfColumns=2)
num1 = random.randint(1,100001)
cmds.text(num1)
cmds.setParent( '..' )

child2 = cmds.rowColumnLayout(numberOfColumns=2)
num2 = random.randint(1,100001)
cmds.text(num2)
cmds.setParent( '..' )

cmds.tabLayout( tabs, edit=True, tabLabel=((child1, 'One'), (child2, 'Two')) )

cmds.showWindow()

标签: pythonmaya

解决方案


我已经修改了您的代码以使其正常工作:

import random
import maya.cmds as cmds
cmds.window(widthHeight=(200, 150))
form = cmds.formLayout()
tabs = cmds.tabLayout(
    innerMarginWidth=5,
    innerMarginHeight=5)
cmds.formLayout(
    form,
    edit=True,
    attachForm=(
        (tabs, 'top', 0),
        (tabs, 'left', 0),
        (tabs, 'bottom', 0),
        (tabs, 'right', 0)))

child1 = cmds.rowColumnLayout(numberOfColumns=2)
num1 = random.randint(1, 100001)
# Save the full path name to the control
text1 = cmds.text(label=num1)
cmds.setParent('..')

child2 = cmds.rowColumnLayout(numberOfColumns=2)
num2 = random.randint(1, 100001)
# Save the full path name to the control
text2 = cmds.text(label=num2)
cmds.setParent('..')

cmds.tabLayout(
    tabs,
    edit=True,
    tabLabel=(
        (child1, 'One'),
        (child2, 'Two')))

cmds.showWindow()

def changer():
    cmds.text(text1, edit=True, label=random.randint(1,100001))
    cmds.text(text2, edit=True, label=random.randint(1,100001))

cmds.tabLayout(
    tabs,
    edit=True,
    changeCommand=changer)

推荐阅读