Anyone knows how to call a function with a button inside a class?
at the moment i have that code:
import maya.cmds as cmds
import maya.mel as mel
from functools import partial
class B:
text_entered="a"
def __init__(self):
self.create_window()
def printText(self):
print(self.text_entered)
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)
self.text_entered = cmds.textField(axis, text=True, query=True)
cmds.button(label="Apply", command = partial(self.printText))
return
B()
But i get that error
# Error: printText() takes exactly 1 argument (2 given) #
Any ideas?
Replies
when you write print(self.text_entered) in this statement it seems like there is 2 arguments or it doesn't return self.text_entered because the def create_window(self) doesn't store (self.text_entered) . maybe try print(self)
sorry my scripting is a bit rusty
def printText(self, *args):
I finally ended with a solution of make a function inside a function: