用于在屏幕上定位窗口的类
我是 Python 新手,这是我的第一堂 Python 课。我在Windows 7上使用PyQt4框架。
我不知道下面几行代码是否正确编写。我想将其进一步修改为:
- 在参数中,我想传递屏幕上另一个打开的窗口(.py)的名称。
- 我将传递 x 坐标、y 坐标。以及要在屏幕上定位的窗口的名称。
如何修改代码来满足这些要求?
进一步编辑
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)
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(self):
screen = QtGui.QDesktopWidget().screenGeometry()
size = self.geometry()
self.move((screen.width()-size.width())/2, (screen.height()-size.height())/2)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你不能只使用
window.setGeometry(x_pos, y_pos, width, height)
吗?在这种情况下,类似乎太过分了。请参阅此处获取文档。
Can't you just use
window.setGeometry(x_pos, y_pos, width, height)
? A class seem overkill in this case.See here for documentation.
您还可以使用
gui.move() 将您的应用程序定位到括号中指定的坐标
You can also use
the gui.move() will position your application to the stated coordinates in the parenthesis