Python - 浏览后更改文本框 - MAYA
我在Maya的图形界面导出工具上遇到了一个非常烦人的问题。我已经让文本框等功能正常工作了,但创建后我无法更改文本框的值,这正是我需要做的。
举个例子,我想一开始文件路径是“无”。这个文本框里现在显示的是:“None”。但是当你点击浏览并选择一个目录后,我希望它能把“None”改成你选择的目录路径。
这就是我目前唯一遇到的问题,收到的错误代码是:
错误:RuntimeError: file C:\Program Files\Autodesk\Maya2015\Python\lib\site-packages\pymel\internal\pmcmds.py line 134: 布局中的子项太多: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!>"
2 个回答
0
看起来你需要在browse()函数中的pm.textField那一行加上编辑标志。
pm.textField("FieldNorm", edit=True, text = "%s" % self.filePath)
0
这个错误的意思是,你在 setupWindow 函数的最后,可能是在给行布局添加一个新的控件,而这个布局里已经有两个按钮了——Maya 认为你在添加第三个按钮。
如果你想在浏览功能中更新 self.textfield 的内容,你需要使用
pm.textField(self.textField, e=True, text = "%s" % self.filePath, editable = False, w = 350, h = 20)
这样可以编辑已经创建的文本框。示例中的那一行
self.textField = pm.textField("FieldNorm", text = "%s" % self.filePath, editable = False, w = 350, h = 20)
其实是在尝试创建一个新的文本框,正如 @julianMann 所指出的。