刷新有关在Maya Python中选择的选项卡

2024-09-29 20:21:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我在Maya Python中有一个tablayout。我试图在每次浏览选项卡时显示一个随机数。在下面我不知道如何刷新标签

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()

Tags: textformtruerandomeditrandintcmdstabs
1条回答
网友
1楼 · 发布于 2024-09-29 20:21:23

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

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)

相关问题 更多 >

    热门问题