Search code examples
pythonpython-3.xcompilationtkintercx-freeze

Python 3.2 Cx_Freeze won't compile whole tkinter


I've made this little calculator which I tried compliling with cx_freeze. It calculates something and gives you the answer in messagebox. Works all fine when I run it from IDLE, but when I run it from .exe, it opens the GUI created with Tkinter, but if I press my calculate button, which should pop up the messagebox, it gives me following error in dos shell:

'Exception in Tkinter callback Traceback (most recent call last): File "C:\Python32\lib\tkinter__init__.py", line 1399, in call return self.func(*args) File "calculator1.pyw", line 46, in energyKinetic NameError: global name 'messagebox' is not defined'

I use the following 'setup.py':

from cx_Freeze import setup, Executable


setup(
    name = 'Kinetic Energy Calculator',
    version = '0.1',
    description = 'Calculate',
    executables = [Executable('calculator1.pyw')],
)

and run it with 'C:\Python32>python setup.py build' from cmd.

The code for calculator itself is just siple Tkinter GUI, with buttons, labels, entries, and messageboxes, so I don't see a reson for posting it here, unless of course someone will find it necessery for me to do so. So, is there anything important I didn't put in the setup.py for it to compile correctly?


Solution

  • You will have to create custom messageboxes with tkinter windows, as the actual ones somehow don't exist when trying to launch a program other than hitting the F5 button. In other words, you can't resolve it. You have to create new windows.