Blog

Use Radio Buttons in a GUI Interface, Maya, Python

Posted by:

Radio buttons are a bit weird, they don’t have queryable data themselves, but they can run functions that will return values.

Here is how I used them:

  1. #Using radio buttons in Maya GUI, Python
  2. #Author: Seth Meshko, 3danimationartist.com
  3.  
  4. import maya.cmds as cmds
  5.  
  6. windowID = 'jfm_radio_button_test'
  7.  
  8. #This is activated if the "Right" radio button in the GUI is active
  9. def rightTrue(*args):
  10. global globalSideOfBody
  11. globalSideOfBody = 'Right'
  12. print('Right is true')
  13. #This is activated if the "Left" radio button in the GUI is active
  14. def leftTrue(*args):
  15. global globalSideOfBody
  16. globalSideOfBody = 'Left'
  17. print('Left is true')
  18.  
  19.  
  20. if cmds.window(windowID, exists=True):
  21. cmds.deleteUI(windowID)
  22.  
  23. cmds.window(windowID, title='Radio_Button_Test', sizeable=True, width = 400)
  24.  
  25. #Start of 1st frame content
  26. cmds.rowColumnLayout(numberOfColumns=4, columnWidth=[(1,75), (2,25), (3,75), (4,25), (5,200)], columnOffset=[(1,'both', 3)])
  27.  
  28. cmds.radioCollection()
  29.  
  30. rightFoot = cmds.radioButton(label = 'Right', editable = True, onCommand = rightTrue)
  31.  
  32. cmds.separator(h=10, style='none')
  33.  
  34. leftFoot = cmds.radioButton(label = 'Left', editable = True, onCommand = leftTrue)
  35.  
  36. cmds.separator(h=10, style='none')
  37.  
  38. cmds.showWindow()
0
  Related Posts

You must be logged in to post a comment.