读取输入后隐藏控制台窗口 [英] Hiding the console window after reading input

查看:47
本文介绍了读取输入后隐藏控制台窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 GUI 的脚本,它获取用户数据并将其存储到文本文件中.它运行另一个脚本(一个 .exe),它等待用户输入然后做一些工作.我想要的是后一个脚本在读取用户输入后隐藏其控制台窗口,但继续在后台工作.

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.

我尝试使用 subprocess.call('lastscript.exe', shell=True)subprocess.Popen('lastscript.exe', shell=True).这不起作用.我必须首先接受用户的输入,然后隐藏控制台并让程序在后台运行.

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.

推荐答案

以下是在 Python 脚本中隐藏 Windows 控制台的代码片段:

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)

这篇关于读取输入后隐藏控制台窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆