Hi Tim: I finally was able to fix this issue in my code. Thanks for your advise. Now I want to share with the community exactly what I did by posting the whole "__init__" method of tkinter's "__init__.py" file:
def __init__(self, screenName=None, baseName=None, className='Tk', useTk=1, sync=0, use=None): """Return a new Toplevel widget on screen SCREENNAME. A new Tcl interpreter will be created. BASENAME will be used for the identification of the profile file (see readprofile). It is constructed from sys.argv[0] without extensions if None is given. CLASSNAME is the name of the widget class.""" self.master = None self.children = {} self._tkloaded = 0 # to avoid recursions in the getattr code in case of failure, we # ensure that self.tk is always _something_. self.tk = None if baseName is None: import os baseName = os.path.basename(sys.argv[0]) # Condition added by Diego Velez so 'tkinter' can be called from COM Servers. --May 18th, 2015 if isinstance(baseName, bytes): baseName = baseName.decode() baseName, ext = os.path.splitext(baseName) if ext not in ('.py', '.pyc', '.pyo'): baseName = baseName + ext interactive = 0 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) if useTk: self._loadtk() if not sys.flags.ignore_environment: # Issue #16248: Honor the -E flag to avoid code injection. self.readprofile(baseName, className) As you can see, I added a condition as soon baseName gets sys.argv[0]. If its of a bytes type it encodes to a string type. I'm sure that my COM servers will work. However, I wonder if this should be the final solution to this "bug"; since I don't know if tkinter should deal with these cases, or the COM servers should not send byte types to python codes. Shouldn't we inform to the guys of Python? Best regards, 2015-05-18 15:14 GMT-05:00 Tim Roberts <t...@probo.com>: > Diego Vélez Torres wrote: > > > > I just fixed the issue by applying your advise. But (...and here comes > > a big BUT !!!), why do I have to do this when calling tkinter inside a > > COM server, meanwhile this is not necessarily when outside a COM? > > You shouldn't. I'm sure this is a bug, but it would take some digging > to assign blame and come up with a fix. If you don't pass a baseName, > the code in tkinter.__init__.py tries to create one from sys.argv[0]. > In a COM server, there may not be a clear value in sys.argv[0]. The > call will fail is baseName ends up None; my guess is that's what is > happening. > > > > If my COM Server were using tkinter directly I could rely on this > > trick. However, my originally problem came up by trying to use pyplot > > from Matplotlib. I found that pyplot.figure() launches a tk > > instance. Therefore, in order to use this library (and any other that > > uses tkinter) within COMs, I must modify the source codes. It doesn't > > seem this to be a feasible solution. Is there any other solution? > > You should be able to modify lib\tkinter\__init.py, and just before the > call at line 1851 insert this: > if baseName is None: > baseName = 'xxx' > > -- > Tim Roberts, t...@probo.com > Providenza & Boekelheide, Inc. > > _______________________________________________ > python-win32 mailing list > python-win32@python.org > https://mail.python.org/mailman/listinfo/python-win32 > -- Diego Vélez Torres divele...@gmail.com Teléfono: 098 28 57 58 Cuenca, Ecuador
_______________________________________________ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32