Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open an external application by pyautogui module in python with predefined window(x,y) position?

I want to open VM player application through python code and I have to import/open VM file but whenever I tried opening the application through subprocess.Popen(self.vmware_path) python code line, it invokes the application at random x,y position.

I have researched some of the possibilities in the subprocess.Popen (STARTUPINOF) but I'm not able to understand the concept of STARTUPINFO class. os.system by this, I could open the application but not able to do it with the predefined position.

    # print pyautogui.position()
    # print pyautogui.size()  # current screen resolution width and height
    # pyautogui.PAUSE = 1
    # pyautogui.FAILSAFE = True

    subprocess.Popen(self.vmware_path)

    # si = subprocess.STARTUPINFO()
    # si.dwFlags = subprocess.STARTF_USESHOWWINDOW
    # si.wShowWindow = 3

Here what I need is,

  1. I have to open VM player application by pyautogui or any other python module along with below support.
    • it should accept predefined window size or
    • it should maximize the application to the actual monitor size.
like image 247
Santhosh Avatar asked Dec 16 '25 19:12

Santhosh


1 Answers

From pyautogui module, not possible to start the application directly.But you can use the os module to launch the application.

Sample:

import os
os.system('start "" "' + path+ '"')

note: path of the application with name

it will launch the application and maximize the screen , then you can use pyautogui to get the screen data(size, position etc).

like image 194
NPC Avatar answered Dec 19 '25 08:12

NPC