1

I have below code which opens the txt file and do maximized window but am unable to bring opened txt file at front also it is able to take screenshot but again not able to close the opened text file...

import os
from tkinter import *
import subprocess
import pyscreenshot as ImageGrab
aaa = "path\file.txt"
a = subprocess.Popen(["cmd","/C","start","/max",aaa])
#need to add code to bring opened window in front
aaa1 = ImageGrab.grab(bbox=(0,0,1000,1000))
aaa1.save(path/aaa.jpg)
a.terminate()                             #this line also does not work
  • If you are on Windows, try to use pywin32 – Demian Wolf Feb 22 '20 at 21:23
  • Does this help? https://stackoverflow.com/questions/6312627/windows-7-how-to-bring-a-window-to-the-front-no-matter-what-other-window-has-fo – Demian Wolf Feb 22 '20 at 21:24
  • I am not able to understand your suggestion, please explain how to use that in my code? – Sachin Kumar Feb 23 '20 at 08:33
  • You need to sleep a while to let the subprocess starts before taking screen shot. Also `a` is the process of `cmd.exe`, not the registered program executed by Windows `start` command to open `.txt` file. So `a.termiate()` will only terminate `cmd.exe`. – acw1668 Feb 24 '20 at 02:42

0 Answers0