Textfield is not returning value to a function in a class

import maya.cmds as mc, os
from functools import partial

class testclass():

def __init__(self,*args):
    if mc.window('win4',exists=1):
        mc.deleteUI('win4')
    mc.window('win4',title='3DreamLib Renamer')
    mc.columnLayout(parent='win4', bgc=[0.2, 0.2, 0.2])
    self.txtFieldSuffix = mc.textField(w=100)
    mc.button(label  = 'button1', c= partial(self.testFunc,arg = mc.textField(self.txtFieldSuffix,q=1,text=1)))
            
    if __name__ == "__main__":
        mc.showWindow('win4')  
    
def testFunc(self,event,arg):
    print ('argument is ',arg)

testclass()

I have a very simple class where I want to get the value of a text field and pass it on to the testFunc. But testFunc print statement prints no value for arg variable. Whatever I write in the textField never gets passed to testFunc. What am I doing wrong?

When you use the query as your argument, it is actually getting called at that point. So you are saving arg as whatever it initially returns.

Rather, you should make the arg that textField, and then query it inside the testFunc. That way it will update fresh each time you run it.

import maya.cmds as mc, os
from functools import partial


class TestClass(object):
    def __init__(self,*args):
        if mc.window('win4',exists=1):
            mc.deleteUI('win4')
        mc.window('win4',title='3DreamLib Renamer')
        mc.columnLayout(parent='win4', bgc=[0.2, 0.2, 0.2])
        self.txtFieldSuffix = mc.textField(w=100)
        mc.button(label  = 'button1', c= partial(self.testFunc,arg = self.txtFieldSuffix))
                
        if __name__ == "__main__":
            mc.showWindow('win4')  
        
    def testFunc(self,event,arg):
        print ('argument is ', mc.textField(self.txtFieldSuffix,q=1,text=1))
        
TestClass()