Joan Venge
Joan Venge

Reputation: 330922

Is there a way to move a window to another monitor using Python?

I need to get a handle to a Window and then move it to my secondary monitor. Is this doable with python 2.6, preferably using the standard libraries.

Upvotes: 8

Views: 8765

Answers (1)

Adam Rosenfield
Adam Rosenfield

Reputation: 400204

Use the pywin32 module to access the native Win32 API. The functions you'll need to use are:

  • EnumWindows to enumerate all of the top-level windows in the system; search for the one you want and save off the window handle
  • EnumDisplayMonitors to enumerate all of the monitors in the system
  • GetMonitorInfo to get the virtual display coordinates of a monitor and to determine whether or not each monitor is the primary monitor
  • MoveWindow to move the window to the desired virtual display coordinates, using the window handle you found earlier

Upvotes: 15

Related Questions