Hiding the console window after reading input

孤者浪人 提交于 2019-12-19 09:58:46

问题


I have a script that has a GUI, which takes user data and stores it into a text file. It runs another script (an .exe), which waits for user input and then does some work. What I want is for the latter script to hide its console window after reading input from the user, but to continue working in the background.

I tried to run that script with subprocess.call('lastscript.exe', shell=True)or subprocess.Popen('lastscript.exe', shell=True). This doesn't work. I have to take input from the user first, and then hide the console and let the program work in the background.


回答1:


Here's a code snippet to hide the Windows console in a Python script:

import ctypes

kernel32 = ctypes.WinDLL('kernel32')
user32 = ctypes.WinDLL('user32')

SW_HIDE = 0

hWnd = kernel32.GetConsoleWindow()
if hWnd:
    user32.ShowWindow(hWnd, SW_HIDE)


来源:https://stackoverflow.com/questions/37206306/hiding-the-console-window-after-reading-input

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