简体   繁体   English

如何隐藏python命令提示符窗口

[英]How to hide a python Command Prompt window

I am working on a program where the user types how old they are. 我正在开发一个程序,其中用户键入他们的年龄。 Which is a raw_input string. 这是一个raw_input字符串。 Once they hit the enter button. 一旦他们按下回车按钮。 So after the user gives me their input. 因此,在用户给我他们的输入之后。 I want the program to go away and run in the background. 我希望程序消失并在后台运行。 And if possible I would like to know how to do this in Windows & Linux systems. 如果可能的话,我想知道如何在Windows和Linux系统中执行此操作。

hi = raw_input("How old are you? ")

On Windows, you can use: 在Windows上,您可以使用:

import ctypes
ctypes.windll.kernel32.FreeConsole()

Given that you started it by a double-click and not from the console. 假设您通过双击而不是从控制台启动它。

For a better solution, I would suggest running the script using pythonw.exe and using a GUI library ( tkinter or something fancier) to display a dialog box instead. 为了更好的解决办法,我建议使用脚本运行pythonw.exe和使用GUI库( tkinter什么票友),显示一个对话框来代替。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM