qt 点击label标签实现打开另一个ui界面
时间: 2023-10-23 14:11:01 浏览: 164
可以使用以下代码实现:
```python
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.setGeometry(200, 200, 300, 300)
self.setWindowTitle("Main Window")
self.label = QtWidgets.QLabel("Click me to open another UI")
self.setCentralWidget(self.label)
self.label.mousePressEvent = self.openUI # 设置label点击事件
def openUI(self, event):
self.anotherUI = AnotherUI()
self.anotherUI.show()
class AnotherUI(QtWidgets.QMainWindow):
def __init__(self):
super(AnotherUI, self).__init__()
self.setGeometry(500, 200, 400, 400)
self.setWindowTitle("Another UI")
self.label = QtWidgets.QLabel("Another UI")
self.setCentralWidget(self.label)
if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
```
当你点击 label 标签时,将会打开另一个 UI 界面。
阅读全文