2

I have a console application written in python using pyinstaller. I need the program window to be hidden (if the user specified it), but at the same time it continued to work in the background, and when you click on the icon again, the previously hidden window just showed. Usually such applications are displayed on the taskbar when you click on the arrow with the text - show hidden icons.

enter image description here

import win32gui
import win32con


def main():
    while True:
        c_out = input(f"Enter command: ")
        if c_out.lower() == 'hide':
            window('hide')


def window(mode: str):
    the_program_to_hide = win32gui.GetForegroundWindow()
    if mode == 'show':
        win32gui.ShowWindow(the_program_to_hide, win32con.SW_SHOW)
    else:
        win32gui.ShowWindow(the_program_to_hide, win32con.SW_HIDE)


main()
Ne1zvestnyj
  • 1,391
  • 1
  • 7
  • 25
  • You mean, like, minimizing it? – Karl Knechtel Jan 23 '22 at 18:56
  • well hide it and leave it to work in the background – Ne1zvestnyj Jan 23 '22 at 19:32
  • You can certainly change `SW_SHOW` and `SW_HIDE` to `SW_RESTORE` and `SW_MINIMIZE`, but that assumes that your terminal window is the foreground window. You don't have any guarantee that will be true. It's a gamble. Console apps in Windows don't own their window. That belongs to the shell. – Tim Roberts Jan 23 '22 at 19:41
  • I need to hide it exactly, and when I click on the exe file on the desktop again to show the running application again, re-read the question – Ne1zvestnyj Jan 23 '22 at 20:05

0 Answers0