I'm having problems using Python tkinter from stealth. I'm running stealth on Python 3.2 (but I think that it is the same with Python 2.7).
Here a very simple snippet that works perfectly when i run it from clean python 3.2 console (not from stealth):
Code: Select all
from tkinter import *
class App:
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.hi_there = Button(frame, text="Hello", command=self.say_hi)
self.hi_there.pack(side=LEFT)
def say_hi(self):
print ("hi there, everyone!")
root = Tk()
app = App(root)
root.mainloop()
The only hackish work around I've found is to force the sys.argv in a way like this:16:04:58:079 []: File "C:\Python32\Lib\tkinter\__init__.py", line 1669, in __init__
baseName = os.path.basename(sys.argv[0])
AttributeError: 'module' object has no attribute 'argv'
Code: Select all
from tkinter import *
import sys
class App:
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.hi_there = Button(frame, text="Hello", command=self.say_hi)
self.hi_there.pack(side=LEFT)
def say_hi(self):
print ("hi there, everyone!")
sys.argv = [""]
root = Tk()
app = App(root)
root.mainloop()
Thank you and thanks to Crome969 that pointed out the problem and gave me an idea on how to solve it.Initialize the Python interpreter. In an application embedding Python, this should be called before using any other Python/C API functions; with the exception of Py_SetProgramName(), Py_SetPythonHome(), PyEval_InitThreads(), PyEval_ReleaseLock(), and PyEval_AcquireLock(). This initializes the table of loaded modules (sys.modules), and creates the fundamental modules __builtin__, __main__ and sys. It also initializes the module search path (sys.path). It does not set sys.argv; use PySys_SetArgvEx() for that. This is a no-op when called for a second time (without calling Py_Finalize() first). There is no return value; it is a fatal error if the initialization fails.