测试Demo
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.QtWidgets import QPushButton
class ScreenGeometry(QMainWindow):
def __init__(self):
super(ScreenGeometry, self).__init__()
self.setWindowTitle("屏幕坐标系")
self.resize(500, 300)
self.btn = QPushButton(self)
self.btn.setText("按钮")
self.btn.clicked.connect(self.onClickButton)
self.move(300, 200)
def onClickButton(self):
print("=" * 24)
print("窗口横坐标 = %d" % self.x())
print("窗口纵坐标 = %d" % self.y())
print("工作区宽度 = %d" % self.width())
print("工作区高度 = %d" % self.height())
print("=" * 24)
print("工作区横坐标 = %d" % self.geometry().x())
print("工作区纵坐标 = %d" % self.geometry().y())
print("工作区宽度 = %d" % self.geometry().width())
print("工作区高度 = %d" % self.geometry().height())
print("=" * 24)
print("窗口横坐标 = %d" % self.frameGeometry().x())
print("窗口纵坐标 = %d" % self.frameGeometry().y())
print("窗口宽度 = %d" % self.frameGeometry().width())
print("窗口高度 = %d" % self.frameGeometry().height())
print("=" * 24)
if __name__ == "__main__":
app = QApplication(sys.argv)
main = ScreenGeometry()
main.show()
sys.exit(app.exec_())
运行效果
========================
窗口横坐标 = 300
窗口纵坐标 = 200
工作区宽度 = 500
工作区高度 = 300
========================
工作区横坐标 = 301
工作区纵坐标 = 238
工作区宽度 = 500
工作区高度 = 300
========================
窗口横坐标 = 300
窗口纵坐标 = 200
窗口宽度 = 502
窗口高度 = 339
========================
图例说明
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200821180705887.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3d6X2NteWM=,size_16,color_FFFFFF,t_70#pic_center)