Hello Don,

I hate Windows but I work with it a lot. I made something similar to a Windows service using PyInstaller and PySide. More specifically, I was making a backup utility. I wanted it to start every time Windows booted up, I wanted it to keep running while Windows was "asleep" and even if the user had been logged out due to inactivity, and I wanted it to not have a window. I achieved all these goals. Here is how I did it:

1. When calling PyInstaller, use the --windowed option. This seems counter-intuitive since we don't want a window, but bear with me. If you use --nowindowed that is *definitely* bad because it will open a CMD.EXE terminal that displays STDOUT from the Python process.

2. We are going to make this a PySide GUI application, at least in theory. Here is a working example:

# File: myapp.py

import threading

from PySide.QtCore import *
from PySide.QtGui import *

class SpecialWindow(QDialog):
    def __init__(self, parent=None):
        super(SpecialWindow, self).__init__(parent)
        self.setWindowTitle("Name of My Application")

        # Make the "minimize" button appear:
        self.setWindowFlags(Qt.WindowMinimizeButtonHint)
        # Without the line above, the "minimize" button may
        # be grayed out on Windows.

special_window = SpecialWindow()
special_window.show()
special_window.showMinimized()
# Calling .showMinimized() is equivalent to clicking the
# minimize button in the corner of the window.

# Whatever your background application is supposed to do,
# put that Python code here. I did this using the Python
# threading library. Here is a little example:

thread = threading.Thread(group=None, target=my_awesome_cool_function, name="My thread")
thread.start()

app.exec_()

# Execution reaches this point when the user closes the application, usually by
# maximizing it and then clicking the X in the corner.

# Clean up your thread and then terminate it.

3. Package myapp.py with PyInstaller, and try it out. Double-clicking myapp.exe should start your Python code, a GUI window will NOT open, and an icon appears in the system tray. When you mouse over the icon, it will say "Name of My Application", or whatever "window title" you set. If you click it, a GUI window will open. You can close this GUI window and thus terminate the app. Alternatively, you can re-minimize the app by clicking in the corner.

4. To make this background application start every time Windows boots up, place myapp.exe in the startup folder. On Windows 8, the startup folder is here:

C:\Users\username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

This should work, I have done it recently.

Good luck,

Zak Fallows

--
You received this message because you are subscribed to the Google Groups 
"PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pyinstaller?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to