Steven Kauffmann wrote: > I have written a small GUI application in python 3.x using the tkinter > module. Program is running fine, but multiple instances of the program > can now be created. I would like to reduce the number of instances of > the program to only 1 instance. I know that this is possible by using > a singleton class. This way it's possible to check if the program is > already running or not. > > When I invoke the program and it detects that the program is already > running, is it then possible to maximize the already running program? > > I can find a lot of examples about singleton classes in python on the > web, but nothing about showing the already running application when 1 > instance of the program already exists. Is there a way to realize this > in python? > > I'm now doing the development on a linux machine, but the final > program should work on Windows.
The singleton pattern will help you ensure that you can create only one instance of the class per process, it doesn't limit the number of processes running the same program. I think a generic way to inform a process about an already running instance of the program is to occupy a previously agreed-upon resource like a file or socket. The Python cookbook has a few recipes, e. g. http://code.activestate.com/recipes/576891/ but the details are tricky to get right and I cannot vouch for the sanity of the one I linked. -- http://mail.python.org/mailman/listinfo/python-list