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:
- In the arguments, I want to pass the name of another opened Window (.py) on the screen.
- 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
精彩评论