python里textfield_Python-浏览后更改textField-MAYA

I've got the most annoying problem with my GUI Exporter in Maya. I've made the textField etc. work, but I can't change the value of the textField after it's created, which is what I need to do.

What I want to do for example is, let's say the filepath is none from the beginning. The textField has now printed out: "None" in it, but after you press browse and select a directory, I want it to change None to the directory path etc.

That's the only problem I currently have and the error code received is this:

Error: RuntimeError: file C:\Program Files\Autodesk\Maya2015\Python\lib\site-packages\pymel\internal\pmcmds.py line 134: Too many children in layout: rowLayout3 #

Code:

#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 ""

#Show the returned window

def showWindow(self, new_window):

if new_window is not None:

pm.showWindow(new_window)

else:

print ""

#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 ""

解决方案

The error means you are adding a new control, probably to the rowlayout at the end of the setupWindow function which holds the two buttons - Maya thinks you're adding a third

If you want to update the contents of self.textfield in the browse functions, you want

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

which will edit the already created field. The line in the example

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

is trying to create a new one, as @julianMann points out

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值