当前位置:   article > 正文

PyQT5 (四)获取控件或窗口坐标的3种方法_pyqt5 控件的位置

pyqt5 控件的位置

 代码:

  1. import sys
  2. from PyQt5.QtWidgets import QApplication, QWidget, QPushButton
  3. def onClick_Button():
  4. print('获取坐标:第一种')
  5. print("widget.x() = %d" % widget.x())
  6. print("widget.y() = %d" % widget.y())
  7. print("widget.width() = %d" % widget.width())
  8. print("widget.height() = %d" % widget.height())
  9. print('获取坐标:第二种')
  10. print("widget.geometry().x() = %d" % widget.geometry().x())
  11. print("widget.geometry().y() = %d" % widget.geometry().y())
  12. print("widget.geometry().width() = %d" % widget.geometry().width())
  13. print("widget.geometry().height() = %d" % widget.geometry().height())
  14. print('获取坐标:第3种')
  15. print("widget.frameGeometry().x() = %d" % widget.frameGeometry().x())
  16. print("widget.frameGeometry().y() = %d" % widget.frameGeometry().y())
  17. print("widget.frameGeometry().width() = %d" % widget.frameGeometry().width())
  18. print("widget.frameGeometry().height() = %d" % widget.frameGeometry().height())
  19. app = QApplication(sys.argv)
  20. widget = QWidget()
  21. btn = QPushButton(widget)
  22. btn.setText('按钮')
  23. btn.move(25,42)
  24. btn.clicked.connect(onClick_Button)
  25. widget.resize(300,240)
  26. widget.move(250,200)
  27. widget.setWindowTitle('获取屏幕坐标系')
  28. widget.show()
  29. sys.exit(app.exec_())

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/218223
推荐阅读
相关标签
  

闽ICP备14008679号