RKh RKh - 1 year ago 83
Python Question

Class to position a window on the screen

I am new to Python and this is my fist Python class. I am using PyQt4 framework on Windows 7.

I don't know whether the few lines of code below is correctly written or not. I want to modify it further as:

  1. In the arguments, I want to pass the name of another opened Window (.py) on the screen.

  2. I will be passing the x-coord., y-coord. and the name of the window to position on the screen.

How to modify the code to fulfill these requirements?

Edited Further

class PositionWindow:
def __init__(self, xCoord, yCoord, windowName, parent = None):
self.x = xCoord
self.y = yCoord
self.wName = windowName;

def center(self):
screen = QtGui.QDesktopWidget().screenGeometry()
size = self.geometry()
self.move((screen.width()-size.width())/2, (screen.height()-size.height())/2)

Answer Source

Can't you just use window.setGeometry(x_pos, y_pos, width, height)? A class seem overkill in this case.

See here for documentation.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download