37259

How do i hide the console window for my app? [duplicate]

Question:

<blockquote>

<strong>Possible Duplicate:</strong><br /><a href="https://stackoverflow.com/questions/466203/how-can-i-hide-the-console-window-in-a-pyqt-app-running-on-windows" rel="nofollow">How can I hide the console window in a PyQt app running on Windows?</a>

</blockquote>

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

What could be the reason for this?

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_())

Answer1:

Use pythonw.exe instead of python.exe

Answer2:

name your file .pyw instead of .py

Answer3:

On default Windows installations, .pyw files are opened without the console window (because they're loaded with pythonw), and .py files load in a console. So yeah, renaming to .pyw is probably easiest solution.

Also - if you're compiling with py2exe, you'll have to change "console=" to "window="

Recommend

  • make tcp server socket class for android with Delphi Xe5
  • (Java/Android) Client-side Socket throwing IOException
  • Embedding pyqtgraph into tab widget Pyqt
  • QtCore.SIGNALS not working on my code
  • Is there a difference between QFileDialog strings in PyQt4 and PyQt5?
  • Qt table last column not stretching to fill in parent
  • Cant send data from Server to client only viceverse using java
  • How to remove this space(margin) from a QWidget form
  • Internationalization of strings with JavaScript Dynamic variable
  • JavaFX CustomMenuItem strange behaviour with TextField
  • Pipe on multiple data in ramda
  • How to add Rating to sort list in Magento 1.7
  • widget create dynamiclly in wordpress plugin
  • How can i get IP Address of my 3G modem?
  • How can I get access to a QMessageBox by QTest
  • Need to find IP address of network interface on Ubuntu with PHP
  • Regex for 1 or 2 or 3 decimal number, no leading zeros, precision 2 and fractions are allowed
  • invalid value in “less” when comparing np.nan in an array
  • Adding to Grid Selection for grid.php file
  • Create a QPaintDevice from HDC handle
  • How to have a QTextBrowser to display contents of a QTextEdit?
  • Multiple values for an AND/OR statement
  • Python kernel dies for second run of PyQt5 GUI
  • Drupal: create a node with employee working hours
  • synology php ftp_ssl_connect - Call to undefined function
  • How to send an std::vector of unsigned char over an UDP socket using boost asio?
  • How to send None with Signals across threads?
  • How to read data from socket connection - android
  • When to use PDO prepared queries. mysql_real_escape error
  • Ansible: setting user on dynamic ec2
  • How to obtain service credentials for a service instance created on IBM Bluemix without binding the
  • Cannot send user message with Spring Websocket
  • How to autoplay video in angularjs?
  • Laravel Eloquent integration in Codeigniter
  • Error in making a socket connection
  • Django foreign key drop down
  • Grails calculated field in SQL
  • How to add date and time under each post in guestbook in google app engine
  • JSON with duplicate key names losing information when parsed
  • Return words with double consecutive letters