Python在浏览MAYA后更改textField

2024-04-27 11:18:24 发布

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

我有一个最恼人的问题,我的图形用户界面导出在玛雅。我已经使textField等工作,但是我不能在textField创建之后更改它的值,这是我需要做的。在

例如,我想做的是,假设文件路径从一开始就没有。textField现在已经打印出:“None”,但是在您按下browse并选择一个目录之后,我希望它将None更改为目录路径等等

这是我目前遇到的唯一问题,收到的错误代码是:

错误:运行时错误:文件C:\Program Files\Autodesk\Maya2015\Python\lib\site packages\pymel\internal\pmcmds.py第134行:layout中的子元素太多:rowLayout3#

代码:

#Setup the window using the returned window

def setupWindow(self, new_window):
    try:
        frame_layout = pm.frameLayout(labelVisible = False, marginWidth = 5, marginHeight = 5)
        pm.columnLayout(w = 350, h = 300)            

        pm.text(label = "Filepath: ")

        self.textField = pm.textField("FieldNorm", text = "%s" % self.filePath, editable = False, w = 350, h = 20)            

        pm.button(label = "Browse", w = 100, h = 20, command = self.browse)
        pm.rowLayout(numberOfColumns = 2, adjustableColumn = 1, w = 350, h = 25)
        pm.button(label = "Export", w = 200, h = 25, command = self.export)
        pm.button(label = "Close", w = 100, h = 25, command = pm.Callback(self.closeButton, new_window))
    except:
        print "<Setting up window failed>"

#Show the returned window        
def showWindow(self, new_window):
    if new_window is not None:
        pm.showWindow(new_window)
    else:
        print "<Window does not exist!>"

#Browse Directory and Paste into textField        
def browse(self, filePath):
    self.filePath = pm.fileDialog2(dialogStyle = 2, returnFilter = 1, fileFilter = "*.obj")

    if self.filePath is not None:
        self.textField = pm.textField("FieldNorm", text = "%s" % self.filePath, editable = False, w = 350, h = 20)
    else:
        print "<No changes has been made!>"

Tags: thetextselfnonefalsenewdefbutton
2条回答

看起来你需要在项目经理文本字段浏览()中的行

pm.textField("FieldNorm", edit=True, text = "%s" % self.filePath)

此错误意味着您正在添加一个新控件,可能是添加到包含两个按钮的setupWindow函数末尾的rowlayout中,Maya认为您正在添加第三个控件

如果要更新的内容self.textfield在browse函数中

   pm.textField(self.textField, e=True, text = "%s" % self.filePath, editable = False, w = 350, h = 20)

它将编辑已创建的字段。示例中的行

^{pr2}$

正如@julianMann指出的那样,他正试图创造一个新的

相关问题 更多 >