Reputation: 889
I have a tablayout
in Maya Python. I'm trying to display a random number every time I navigate through the tab. In the following I'm not getting how to refresh the tab
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()
Upvotes: 0
Views: 312
Reputation: 1803
I've modified your code to make it work:
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)
Upvotes: 1