无法在optionMenu changeCommand函数中更改Python文本命令

2024-09-29 22:20:30 发布

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

我已经创建了一个UI,它有一个下拉列表和一个按钮。我试图添加一个错误消息,如果按钮被点击,但没有选择任何东西在下拉列表中。我在按钮点击功能中添加了错误信息,它运行得非常好。我的问题发生在我试图在change命令函数中清除/隐藏消息时。我得到错误'太多的孩子在布局'。我阅读了布局元素需要包含父元素的地方,所以我确保所有内容都是父元素。我尝试了setParent和元素的parent属性,但是没有什么区别。我尝试将errRowLayout上的列数更改为2。这消除了布局错误,但没有清除我的信息。我还发现代码可以在其中一个函数中工作,但不能同时在两个函数中工作。我整个下午都在拼命想办法解决这个问题。我肯定我忽略了一些很简单的事情。你知道吗

这些是相关的代码行。你知道吗

# this is called from another function
def createCustom(self):
    self.characterOptionMenu = pm.optionMenu('characterOptionMenu',  w=self.windowWidth, label=' Choose a Character:', changeCommand=self.item_change, parent=self.mainLayout)      
    self.errRowLayout = pm.rowLayout(numberOfColumns=1, columnWidth=[1, self.windowWidth], columnAlign=[1, 'center'], parent=self.mainLayout)
    self.buttonRowLayout = pm.rowLayout(numberOfColumns=1, width=self.windowWidth, parent=self.mainLayout)
    pm.button("Setup Character", w=self.windowWidth, h=30, command=self.setup_button_click, parent=self.buttonRowLayout)I 

def setup_button_click(self, *args):
    selectedCharacter = pm.optionMenu(self.characterOptionMenu, q=True, value=True)

    if selectedCharacter == ' ':
        # create the error message
        # this statement works
        pm.text(label='Character cannot be blank.', visible=True, backgroundColor=[250, 128, 114], font='boldLabelFont', width=self.windowWidth, parent=self.errRowLayout)
        return

def item_change(self, *args):
    selectedCharacter = pm.optionMenu(self.characterOptionMenu, q=True, value=True)
    # this statement gives me the layout error 
    pm.text(label='', visible=False, parent=self.errRowLayout)

非常感谢您的帮助。你知道吗


Tags: 函数selftrue元素def错误布局this
1条回答
网友
1楼 · 发布于 2024-09-29 22:20:30

看起来您正在创建一个新的文本标签。在setup\u button\u click()中,您已经创建了一个文本标签,然后尝试使用相同的父项创建另一个文本标签。这应该可以解释这个错误。你知道吗

请参阅以下文档:

http://download.autodesk.com/us/maya/2011help/commandspython/text.html

您可能应该尝试获取文本标签控件的完整路径名,然后使用edit=true调用text()。你知道吗

相关问题 更多 >

    热门问题