bin neu und noch Anfänger im Bereich Python.
Ich möchte z.b. Notepad Starten!
Ist es aber gestartet, möchte ich es nicht ein 2 mal Starten, sondern das bereits gestartete Notepad, soll in den Vordergrund gesetzt werden.
Hier mein Programm welches aber nicht funktioniert!
Es wird einfach eine neue instanz von Notepad geöffnet!
Warum? in der If abfrage wird doch geschaut ob es bereits ein Window (Notepad) gibt und er soll es in den "SetForegroundWindow" setzen.
Was mache ich falsch?
Code: Alles auswählen
import subprocess
import win32gui
def open_notepad():
try:
hwnd = win32gui.FindWindow(None, 'Notepad')
if hwnd:
win32gui.SetForegroundWindow(hwnd)
else:
subprocess.Popen('notepad')
except Exception as e:
print("Fehler beim Öffnen von Notepad:", str(e))
open_notepad()
Gruß
Kumpelblase