Hiding the console window

佐手、 提交于 2019-12-10 20:04:59

问题


problem

I started designing GUI applications using Python and Tkinter. When I freeze a script using cxFreeze then when I run that EXE file on a machine. Then first the console window (a black DOS shell in the case of Windows XP) opens and then the main window(Tk() instance) gets initialized.

goal

The console window must not appear. Only the Tk() instance should appear.

code

root = Tk()

Label(root,text="hey").pack()

root.mainloop()

specs

Windows XP SP 3

Python 2.7

Tkinter 8.5


回答1:


When using py2exe use windows=['main.py'] instead of console=['main.py'] when creating your setup.py

For cx_Freeze this answer might help you: https://stackoverflow.com/a/11374527/2256700




回答2:


I'm not sure if this is the answer anyone is looking for, but renaming the file extension from .py to .pyw under Python 3.4 and Win32 will effectively suppress the Python shell. You'll just get your Tk GUI window.




回答3:


Say your python script is called "myscript.py".

Create a file called runme.vbs containing code:

Set WshShell = CreateObject("WScript.Shell")
cmds=WshShell.RUN("myscript.py", 0, True)
Set WshShell = Nothing


来源:https://stackoverflow.com/questions/15896062/hiding-the-console-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!