I have a script with a wx.Python GUI that monitors game files for changes and then makes a .tar.gz backup of each turn. If I run the test script (.py extension) the program works well and I can play the game without noticing the python script running in the background. When the script is run a console window is opened at the same time because of the .py extension.

So I tried to package the script as an exe using Py2Exe so I can share it, and while the script runs properly and does its job, every time it makes the .tar.gz and updates a text control in the GUI, the game minimises and the focus is given to the GUI. I don't want this to happen as it is very disjointed trying to play the game. The game should stay open all the time and the GUI should just update itself quietly in the background as it makes its archives.

Then I tried changing the .py extension to a .pyw extension to not open the console window. Once again, the program does what it is supposed to as far as backing up the changes, but this also minimises the game every time it creates an archive and gives focus to the GUI.

My questions are:

1. By appending content to a text control, does this demand the window focus if there isn't a console running?
2. Is there a way for me to run the application and not have it focus on itself when it does something?
3. Why does it remain hidden when the console window is open (.py files) but demand the focus as a .exe or .pyw?

I really hope someone can help me with this problem as I am now in the home stretch as far as completing this project and this seems to be the last of my problems.

I've done a little more detective work to try and isolate the command that was causing the problem. Originally I had guessed it was when the GUI updated that it wanted the focus back again. Then I thought it may have been when the archive was created.

But the actual command that is causing the game to minimise is a call to the .exe of the game itself that generates turn information.

os.system('dom3.exe ' + gameName + ' --verify')

When implemented from the GUI it minimises the current game window. When implemented from the console it doesn't minimise the game.

Not sure where to take this next.

Just a guess, but this approach is supposed to behave better then os.system() ...

import subprocess
# ...
subprocess.call(["dom3.exe", gameName, "--verify"])
This question has already been answered. Start a new discussion instead.