Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class to position a window on the screen

Tags:

python

pyqt

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)
like image 900
RKh Avatar asked Jan 09 '11 01:01

RKh


2 Answers

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

See here for documentation.

like image 147
Francesco Pasa Avatar answered Nov 14 '22 23:11

Francesco Pasa


You can also use

def main():
    app = QtGui.QApplication(sys.argv)
    gui = Program()
    gui.move(380, 170)
    gui.show()
    app.exec_()

the gui.move() will position your application to the stated coordinates in the parenthesis

like image 24
And3r50n 1 Avatar answered Nov 14 '22 22:11

And3r50n 1