Maya中Python编写UI出现未知错误技术求助
问题排查:Maya Python UI代码未知错误
Hey there, let's fix the issues in your Maya UI code right away—there are two straightforward syntax problems causing the error:
1. 无效的注释格式
第一行的 User Interface Window 没有使用Python的注释语法,Python会把它当作可执行代码,直接触发语法错误。我们需要给它加上 # 变成合法注释。
2. 括号不匹配
在调用 cmds.rowColumnLayout() 的那一行末尾,你漏掉了一个闭合的右括号 ),这会导致Python无法识别完整的函数调用,进而抛出语法异常。
修正后的完整代码
# User Interface Window import maya.cmds as cmds class UserInterface(): def __init__(self): windowID = "myWindowID" if cmds.window(windowID, exists = True): cmds.deleteUI(windowID) cmds.window(windowID, title="User Interface", sizeable=False, resizetoFitChildren=True) cmds.rowColumnLayout(numberOfColumns=3,columnWidth=[(1,75), (2,60), (3,60)], columnOffset=[(1,"right",3)]) cmds.showWindow()
你可以把这段修正后的代码导入Maya测试,窗口应该能正常显示了。如果之后还要添加UI控件(比如按钮、输入框),只需要在 rowColumnLayout 和 showWindow() 之间插入对应的 cmds 控件调用即可。
内容的提问来源于stack exchange,提问作者Kazi
相关产品推荐
相关产品推荐

