我正在尝试在函数中创建一个按钮来调用类中的另一个函数。
这就是我所做的:
# button calling functions
import maya.cmds as cmds
import maya.mel as mel
from functools import partial
class B:
def __init__(self):
self.create_window()
def printText(self, text, *args):
print(text)
return
def create_window(self):
window = cmds.window()
cmds.rowColumnLayout(numberOfColumns=2, columnWidth=[(1, 50), (1, 70)])
cmds.text(label='Name')
axis = cmds.textField()
cmds.showWindow(window)
text_entered = cmds.textField(axis, query=True, text=True)
#cmd = 'printText("{0}")'.format(text_entered)
cmds.button(label="asd", command = partial(self.printText, text_entered))
return
a = B()
问题是我什么也没打印出来。我做错了什么?
最佳答案
找到了一个解决方案,但我觉得有点奇怪
import maya.cmds as cmds
class B:
def __init__(self):
self.create_window()
def create_window(self):
if cmds.window("UI", exists=True):
cmds.deleteUI("UI")
win = cmds.window("UI")
cmds.columnLayout()
textEntered = cmds.textField()
def print_text_contents(a):
print cmds.textField(textEntered, query=True, text=True)
cmds.button(label='Confirm', command=print_text_contents)
cmds.showWindow(win)
B()
关于python - 在 Maya 中调用函数的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45427554/