+ 1
Is there a way to close other windows?
Does anyone know , if there is a way, how to close a non python window from a python window for example closing a Note Pad window? If anyone knows the line of code so I can allow a tkinter window control other windows using buttons... 😊 Cheers
7 Respuestas
+ 7
You can import subprocess and use a call method to invoke the taskkill.exe. This should do the trick:
import subprocess
subprocess.call(['taskkill', '/IM', 'notepad.exe'])
# closes the Notepad or displays an error (does not raise an exception!) if Notepad not open
EDIT: just read the help of taskkill and closing the Notepad is the very first example there! ;)
+ 4
BTW, let me know if that worked for you. I tried it on my Win7 and it worked, but I have a pretty simple setup. While taskkill can be pretty powerful... :)
+ 4
@Kirk From what I read, it can try to terminate (possibly spawning the confirm window) or forcefully kill a process, even with all other dependent subprocesses.
+ 4
@Kirk Just if you were wondering -- yes, I already tried it in Sololearn, as Python here runs on Windows virtual machine. They got it covered, though, as access to all default applications is denied (that still means that they are there!) :)
https://code.sololearn.com/chDD2bSY225G/?ref=app
+ 2
In plain old Windows Scripting Host (e.g., vbscript), you would "AppActivate" the desired window by title and then send the appropriate key sequence with SendKeys.
There's a SendKeys implementation for Python 2.x (I can't test it):
https://pypi.python.org/pypi/SendKeys
And this method can apparently dispatch to wscript directly:
https://win32com.goermezer.de/microsoft/windows/controlling-applications-via-sendkeys.html
Edit: Searching, there seems to be a lot of ideas out there (e.g., using ctypes, etc), but not having a Windows box is interfering with me being more specific.
+ 2
Yup worked perfectly thanks alot Kuba Siekierzyński !!!! 😊😊😊😊
+ 2
@Kuba - Just curious... Does notepad get to run the modal "Save" dialog (or is it literally a force quit, the process is brickwalled)?