我創建了一個具有下拉列表和一個按鈕的UI。我試圖添加一個錯誤消息,如果按鈕被點擊但沒有在下拉列表中被選中。我在按鈕點擊功能中添加了錯誤消息,並且它完美地工作。當我嘗試在更改命令功能中清除/隱藏消息時,會出現問題。我得到錯誤'佈局中太多兒童'。我閱讀了包含父項的佈局元素所在的位置,以確保所有內容都是父項。我嘗試了setParent和元素的父屬性,但它沒有什麼區別。我嘗試將errRowLayout上的列數改爲2.這樣擺脫了佈局錯誤,但它沒有清除我的消息。我還發現代碼可以在其中一個或另一個函數中使用,但不能同時使用這兩種。整個下午我都在試圖弄清楚這個問題,一直在撞牆。我相信這可能是我忽視的一些非常簡單的事情。無法更改optionMenu中的Python文本命令changeCommand函數
這些是相關的代碼行。
# 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)
所有幫助非常感謝。
謝謝,@Icyvapor。我明白你在說什麼。我試圖更新該文本標籤而不是創建另一個文本標籤。考慮到這一點,我嘗試將文本標籤分配給setup_button_click函數中的變量。然後我在item_change函數中將該變量的可見屬性設置爲False。雖然更改屬性並未隱藏錯誤消息。我是否需要刷新某些內容才能識別可見屬性的新值? – doubler