On Mon, Apr 17, 2017 at 8:11 AM gnn <[email protected]> wrote: > Hello, i need to make an ui layout in python inside maya, > it is asking some questions and when the button is pressed, > put the entries of intField or textField into variables... > very simple but i can't find the solution: "if button pressed?"... > thanks for any help!! > > import maya.cmds as cmds > window = cmds.window(title = "Open Last scene", width = 150, height = 100) > cmds.rowColumnLayout( numberOfColumns=2, columnAttach=(1, 'left', 0), > columnWidth=[(1, 100), (2, 250)] ) > cmds.text( label='Episode: ', align='left' ) > cmds.intField( "Episode", minValue = 0, maxValue = 100, value = 0) > cmds.separator( h=5, style='none' ) > cmds.rowColumnLayout( numberOfColumns=1, columnAttach=(1, 'left', 0), > columnWidth=[(1, 100), (2, 250)] ) > cmds.button('Open', l="Open Last scene", w=180, h=30) > cmds.showWindow() > > #if button pressed?? > #put the intField into a variable: > EpisodeName = `cmds.intField( "Episode", query = True, value = True)` > print EpisodeName >
If you take a glance at the docs for "button", at the bottom you will see an example of making use of the 'command' parameter. This param takes either a python string to evaluate, or a callback object (preferred) http://help.autodesk.com/cloudhelp/2016/ENU/Maya-Tech-Docs/CommandsPython/button.html So in your case, to fill in the "#if button pressed" section, you would put that into a callback function, and then tell the button to call it when clicked: def buttonPressed(*args): print "button pressed" cmds.button('Open', l="Open Last scene", w=180, h=30, command=buttonPressed) > -- > You received this message because you are subscribed to the Google Groups > "Python Programming for Autodesk Maya" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/66af5f58-f7f6-4173-ab4e-0b8b842c0cfe%40googlegroups.com > <https://groups.google.com/d/msgid/python_inside_maya/66af5f58-f7f6-4173-ab4e-0b8b842c0cfe%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3H_kM3F4V%3Dkf_5HzPQddyy_hvcvW5eH3v8kJEv%2BG4Pbw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
