wxPython and Maya 8.5

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
  01 January 2007
wxPython and Maya 8.5

Has anyone tried importing wx or Tkinter yet under Maya 8.5 and using them to build user interfaces with Maya 8.5's python integration? If so what was your experience? Did it work? Are there any issues to be aware of? So far I've only converted some of my existing MEL scripts to Python using the Maya/Python UI calls. This works fine but I'm interested if the wxpython modules might also work.

--Randy Stebbing
Randy Stebbing
  01 January 2007
I would like to know if anyone has had any success with this as well.

Any examples of working scripts would be great.
mike hovland
lead technical artist

Life beats down and crushes the soul... art reminds you that you have one. - Stella Adler
  01 January 2007

Are you asking for specific WX Python examples working under Maya or just examples of converted Mel scripts re-written to work using the Python calls?

My initial question was asking about the possiblity of wxPython integration. And I'm still hoping that someone can report flawless integration with wxPython as this could really open up the types of userinterface toolset available for Maya.

For those wondering about the more general Python/Maya integration I can report that Autodesk has done a great job at providing Python specific documentation to each command. All the Mel documentation examples have been converted to give corresponding Python/Maya examples.
--Randy Stebbing
Randy Stebbing
  01 January 2007
I was asking about UI integration using wxWidgets.
mike hovland
lead technical artist

Life beats down and crushes the soul... art reminds you that you have one. - Stella Adler
  01 January 2007
I'm really wondering if this could work too. Building UI's in Maya as we all now really sucks. However both Tkinker and wxPython would really step it up with having some really robust applications inside of maya.

Here is some help from Autodesk with regards to this. Haven't tried it yet. Hoping someone would give this a go and let us know if they had any success.

Quote: Issue

When I try this in the Script Editor in Python Mode:

from Tkinter import *

I get this error:

# File "C:\Program Files\Autodesk\Maya8.5\Python\lib\lib-tk\Tkinter.py", line 38, in ?
# import _tkinter # If this fails your Python may not be configured for Tk
# ImportError: No module named _tkinter


You need to find the _tkinter.so or .pyd in a separate installation of Python and put that into your PYTHONPATH for Maya to find it. _tkinter is not included with the Python distribution in Maya itself. You can look in the Python/DLLs directory to see which compiled modules are being distributed with Maya.

Note: Tkinter is not support within Maya at this current time.

If this would work, I've been dying to make a component editor that works. Having looked at some of the gridLayouts used in wxPython I was blown away by simple it is to create.


  01 January 2007
Keep us informed. I'm really eager to find out if this works too. It would really make gui creation for tools so much easier.

  01 January 2007
It would be especially nice if a wxPython solution could be found. Then we could use the same GUI setup for both Maya and XSI. This would greatly help integration between the two.

  01 January 2007
Originally Posted by arcsecond: It would be especially nice if a wxPython solution could be found. Then we could use the same GUI setup for both Maya and XSI. This would greatly help integration between the two.


this would be indeed neat!! so wxPython works with XSI as well?
  01 January 2007

apparently so. I haven't had time to experiment with it yet. Looks like you have to do a little work and write your own frame subclass. But it appears that you can make it think it's a child of the main XSI window.

I was trying to do the same thing with Tkinter but ran up against roadblocks. When you have the Tk window open it steals focus from the main XSI window and you can't do anything in the main XSI window until you close the Tk window. I suppose it might be possible to do the integration trick with a subclassed frame in Tk the same way it's being done in wx.

I REALLY need to find some time to experiment.

  01 January 2007
Gets the same result here with Maya. Tk works but it freezes Maya until you quit the Tk UI.
Will digg deeper into this.

Fredrik Brännbacka | Technical Director
mail: fredrik@madcrew.se
web: http://www.madcrew.se
  01 January 2007
The reason this is happening is because the gui is stuck in a loop and never give control back to maya. One way to get around this would be to send the interface call to a thread. This would free maya back up to do what it needs to do while the interface loop is doing its thing in a thread. One of the problems i can see with doing this is that maya commands themself are not thread safe, meaning that you will have to use the "executeInMainThreadWithResult" command in order to use them. maya.utils.executeInMainThreadWithResult( command, arg1, arg2 )Seems like a huge pain though.
Keith E. Lackey
Technical Director
  02 February 2007
Hmm I don't know about Tkinter but after several hours of struggling I was able to launch wxPython inside Maya 8.5 by modifying Aloys Baillets files for XSI. No focus problem or freezing stuff what so ever. At least I haven't noticed any such behaivor yet.
The only bad news is that I wasn't able to run it inside 7 using cgkit's Python-plugin. Anyone had luck with that?

Edit: Ops! I forgot to change title name of the application it tries to find (since Maya 7 is called "Maya 7" and Maya 8.5 is called "Autodesk Maya...". So there is no bad news! It works on 7 as well (as long as you use Windows, otherwise this entire hack won't work at all)


Last edited by Pedalen : 02 February 2007 at 05:30 PM.
  02 February 2007
Rock on! I don't suppose you'd mind posting your solution?

Can't wait until my studio upgrades to 8.5 and I can start applying some of this stuff.

  02 February 2007
Here's the Aloys Baillet's code stripped down and functioning in Maya.

To use:
1. save code to a file called WxMaya.py (or whatever you want to call it) and place in scripts directory
2. in Maya type:

import WxMaya

import os
        import wx
        import traceback
        import win32gui, win32process
        class MayaSubFrame(wx.Frame):
        	_topLvlMayaWinHandle = None
        	def create(cls,*args,**kw):
        		app = wx.GetApp()
        		if app is None:
        			app = wx.App(redirect=False)
        		topHandle = MayaSubFrame._getMayaTopWindow()
        		top = wx.PreFrame()
        		print topHandle
        			frame = cls(top,app,*args,**kw)
        			print cls.__name__
        			print traceback.format_exc()
        			frame = None
        		return frame
        	def _getMayaTopWindow():
        		if MayaSubFrame._topLvlMayaWinHandle is not None:
        			return MayaSubFrame._topLvlMayaWinHandle
        		def callback(handle,winList):
        			return True
        		wins = []
        		win32gui.EnumWindows(callback, wins)
        		currentId = os.getpid()
        		for handle in wins:
        			tpid,pid = win32process.GetWindowThreadProcessId(handle)
        			if pid == currentId:
        				title = win32gui.GetWindowText(handle)
        				if title.startswith("Autodesk Maya"):
        					MayaSubFrame._topLvlMayaWinHandle = handle
        					return handle
        		return None
        	def __init__(self,parent,app,id,title,pos=(150,150),si  ze=(320,240),style=wx.DEFAULT_FRAME_STYLE|wx.FRAME  _FLOAT_ON_PARENT|wx.FRAME_NO_TASKBAR):
        		wx.Frame.__init__(self,parent,id,title,pos,size,st  yle)
        		self.app = app
        		self.panel = None
        	def OnClose(self,event):
        		win32gui.SetFocus(MayaSubFrame._topLvlMayaWinHandl  e)
        class MayaFrame(MayaSubFrame):
        	def __init__(self,parent,app):
        		MayaSubFrame.__init__(self,parent,app,-1,"Maya WxFrame",size=(320,240))
        def createMayaFrame():
        	return True

Note: Do not copy/paste this to the script editor and try to run it there. The script looks for a process id that returns "Autodesk Maya" and running from the script editor actually returns the id of "Output Window" which will cause the script to fail.

The script is totally stripped down and is only a blank wxFrame. I appologize for the total lack of comments.

I hope that this works as well for everyone else. If you have any sort of issues with this script, please post your results here.
"The secret to creativity is knowing how to hide your sources." -- Albert Einstein
  02 February 2007
Awesome, that's a lot more striped down than I was able to do. Will be using this instead of my noobish code
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright ©2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 12:44 PM.

Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.