setGeometry
时间: 2024-05-14 21:14:20 浏览: 82
setGeometry() is a method in PyQt5 that sets the size and position of a widget in the form of (x, y, width, height). The first two parameters specify the position of the top-left corner of the widget, while the last two specify the width and height of the widget.
For example, if we want to create a window with a size of 500 x 500 pixels and position it at (100, 100) on the screen, we can use the following code:
```python
import sys
from PyQt5.QtWidgets import QApplication, QWidget
app = QApplication(sys.argv)
window = QWidget()
window.setGeometry(100, 100, 500, 500)
window.show()
sys.exit(app.exec_())
```
Here, we create a QWidget (window) and use setGeometry() to set its position to (100, 100) and its size to 500 x 500 pixels. We then call the show() method to display the widget on the screen. Finally, we use sys.exit(app.exec_()) to start the event loop and exit the application when the window is closed.
阅读全文