开发者

Class to position a window on the screen

开发者 https://www.devze.com 2023-02-03 11:33 出处:网络
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 furthe

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(开发者_StackOverflowself):
        screen = QtGui.QDesktopWidget().screenGeometry()
        size = self.geometry()
        self.move((screen.width()-size.width())/2, (screen.height()-size.height())/2)


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

See here for documentation.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消