如何隐藏我的应用程序的控制台窗口? [英] How do i hide the console window for my app?

查看:64
本文介绍了如何隐藏我的应用程序的控制台窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
如何隐藏在 Windows 上运行的 PyQt 应用程序中的控制台窗口?

我制作了一个简单的应用程序,它可以打开一个 QWebView,但除了打开 Windows 控制台窗口的应用程序窗口之外.

I've made a simple app that opens a QWebView but in addition to the app window Windows console window is opened to.

这可能是什么原因?

import sys
import socket
from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import QWebView

class AppWindow(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)        

        self.setGeometry(300, 300, 200, 25)  
        self.setWindowTitle('TrayIP')
        self.create_sys_tray()      

        self.hostname = socket.gethostname()
        self.ip = socket.gethostbyname(self.hostname)

        self.label = QLabel("IP: " + self.ip, self)
        self.label.setFont(QtGui.QFont('Helvetica', 14))

        self.timer = QTimer()
        self.connect( self.timer, QtCore.SIGNAL('timeout()'), self.timerupdate)
        self.timer.start(10000)

    def timerupdate(self):
        self.web = QWebView()
        self.web.load( QUrl('http://xxx') )

    def create_sys_tray(self):
        self.sysTray = QtGui.QSystemTrayIcon(self)
        self.sysTray.setIcon( QtGui.QIcon('ico.ico') )
        self.sysTray.setVisible(True)
        self.connect(self.sysTray, QtCore.SIGNAL("activated(QSystemTrayIcon::ActivationReason)"), self.on_sys_tray_activated)

        self.sysTrayMenu = QtGui.QMenu(self)
        act = self.sysTrayMenu.addAction("FOO")

    def on_sys_tray_activated(self, reason):        
        if self.isVisible ():
            self.setVisible(False)
        else:
            self.setVisible(True)

app = QtGui.QApplication(sys.argv)
window = AppWindow()
window.show()
sys.exit(app.exec_())

推荐答案

使用 pythonw.exe 而不是 python.exe

Use pythonw.exe instead of python.exe

这篇关于如何隐藏我的应用程序的控制台窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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