3

Hi When I compile my python script with py2exe, everything works well except a usless command-line dialog appears as well as my GUI. Any way to fix this? I have python 2.7 and my setup script looks like this:

from distutils.core import setup
import py2exe
setup(console=['Main.py'])  

Please help!

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Python Kid
  • 313
  • 2
  • 7
  • 19

2 Answers2

14

Using setup(windows=['Main.py']) should remove the command line dialog and use Main.py as your console, instead.

octopusgrabbus
  • 10,555
  • 15
  • 68
  • 131
Amr
  • 695
  • 4
  • 11
  • So my code should look like this: `from distutils.core import setup import py2exe setup(windows=['Main.py'],console=['Main.py'])` – Python Kid Jun 18 '12 at 17:31
  • Still not working even with `windows=['Main.py']` please help – Python Kid Jun 19 '12 at 16:23
  • By it's not working do you mean that you still see the console window? – Amr Jun 19 '12 at 17:35
  • I haven't really used py2exe before, but if you still see the console window after using `windows=` instead of `console=` then maybe it's because there are errors redirected to `stdout` see [here](http://www.py2exe.org/index.cgi/GuiApps) for more info. – Amr Jun 19 '12 at 17:37
  • No I just don't see anything, Is it because in main.py I don't use tk.mainloop()? – Python Kid Jun 22 '12 at 18:49
  • 1
    It was because i didn't use root.mainloop(). – Python Kid Jun 26 '12 at 18:47
4

Rename your entry point python script extension from .py to .pyw and regenerate your exe.

Example: python -m py2exe.build_exe -b 0 my_script.pyw

(tested with Python 3.4.3 on Windows 8.1 x64)

Example: my_script.pyw

import ctypes
MessageBox = ctypes.windll.user32.MessageBoxW
MessageBox(None, 'Hello', 'Hello Window Title', 0)

You should not see a command prompt for this GUI application.

Adam Gradzki
  • 139
  • 2
  • 9