from PyQt5 import QtCore, QtGui, QtWidgets from show1 import Ui_Form1 from show2 import Ui_Form2 from show3 import Ui_Form3 class Ui_Form(object): def setupUi(self, Form): Form.setObjectName("Form") Form.resize(400, 300) self.pushButton = QtWidgets.QPushButton(Form) self.pushButton.setGeometry(QtCore.QRect(90, 60, 191, 51)) font = QtGui.QFont() font.setPointSize(9) self.pushButton.setFont(font) self.pushButton.setObjectName("pushButton") self.pushButton_2 = QtWidgets.QPushButton(Form) self.pushButton_2.setGeometry(QtCore.QRect(90, 110, 191, 51)) self.pushButton_2.setObjectName("pushButton_2") self.pushButton_3 = QtWidgets.QPushButton(Form) self.pushButton_3.setGeometry(QtCore.QRect(90, 160, 191, 51)) self.pushButton_3.setObjectName("pushButton_3") self.retranslateUi(Form) QtCore.QMetaObject.connectSlotsByName(Form) def retranslateUi(self, Form): _translate = QtCore.QCoreApplication.translate Form.setWindowTitle(_translate("Form", "Form")) self.pushButton.setText(_translate("Form", "无人机群显示")) self.pushButton_2.setText(_translate("Form", "无人机群数据分析展示")) self.pushButton_3.setText(_translate("Form", "无人机群飞行轨迹展示")) class MainWindow(QtWidgets.QMainWindow): def __init__(self): super().__init__() self.ui = Ui_Form() self.ui.setupUi(self) self.ui.pushButton.clicked.connect(self.showForm1) self.ui.pushButton_2.clicked.connect(self.showForm2) self.ui.pushButton_3.clicked.connect(self.showForm3) def showForm1(self): self.form1 = QtWidgets.QWidget() self.ui1 = Ui_Form1() self.ui1.setupUi(self.form1) self.form1.show() def showForm2(self): self.form2 = QtWidgets.QWidget() self.ui2 = Ui_Form2() self.ui2.setupUi(self.form2) self.form2.show() def showForm3(self): self.form3 = QtWidgets.QWidget() self.ui3 = Ui
时间: 2024-03-14 19:49:21 浏览: 124
_Form3() self.ui3.setupUi(self.form3) self.form3.show()
这段代码是一个基于PyQt5的GUI程序,它创建了一个主窗口并在窗口中添加了三个按钮。当用户单击按钮时,程序会打开另外三个窗口,分别用于显示无人机群的位置、数据分析和飞行轨迹。这个程序的核心是MainWindow类,它继承自QtWidgets.QMainWindow,并在__init__方法中创建了UI对象并连接了三个按钮的clicked信号到对应的槽函数showForm1、showForm2和showForm3。这三个槽函数分别创建了对应的窗口对象,并在窗口中添加了对应的UI组件,并将窗口显示出来。
相关问题
PYQT5点击按钮弹出from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Form(object): def setupUi1(self, Form):
在使用PyQt5中,`Ui_Form` 类似于Qt Designer生成的一个UI描述类,它包含了对窗体或控件的基本布局和属性信息。`setupUi1` 是你自定义的方法,用于初始化和配置由Qt Designer设计的界面。
当你在代码中点击某个按钮,如`QPushButton`,通常需要关联一个槽函数,也就是一个Python函数,以便在按钮被触发时执行某些操作。例如,你可以这样设置按钮的点击事件:
```python
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton
from PyQt5 import QtCore, QtGui, QtWidgets
from .ui_form import Ui_Form # 这里假设ui_form.py包含了Ui_Form类
class MyWindow(QMainWindow, Ui_Form): # 继承自QMainWindow和Ui_Form
def __init__(self):
super(MyWindow, self).__init__()
self.setupUi(self) # 设置UI布局
# 获取QPushButton的实例,这里假设按钮名为"pushButton"
button = self.findChild(QtWidgets.QPushButton, 'pushButton')
# 定义槽函数,当按钮被点击时执行
button.clicked.connect(self.show_popup)
def show_popup(self):
# 当按钮被点击时,可以在这里编写弹出新窗口或对话框的代码
popup = QtWidgets.QDialog() # 创建一个简单的对话框
popup_ui = Ui_biaoding() # 如果有另一个UI Form, 则创建相应类的实例
popup_ui.setupUi(popup) # 初始化UI
# 显示对话框
popup.exec_()
```
在这个例子中,当`pushButton`被点击时,`show_popup`函数会被调用,其中创建了一个新的`QDialog`对象,并设置了`Ui_biaoding`的UI。如果你没有定义`Ui_biaoding`,则需要将其替换为实际的子窗口或对话框类。
# -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'untitled.ui' # # Created by: PyQt5 UI code generator 5.15.4 # # WARNING: Any manual changes made to this file will be lost when pyuic5 is # run again. Do not edit this file unless you know what you are doing. import sys from ui import ui from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Form(object): def setupUi(self, Form): super().__init__() Form.setObjectName("Form") Form.resize(633, 434) self.label = QtWidgets.QLabel(Form) self.test = ui() self.label.setGeometry(QtCore.QRect(110, 50, 54, 12)) self.label.setObjectName("label") self.label_2 = QtWidgets.QLabel(Form) self.label_2.setGeometry(QtCore.QRect(110, 80, 54, 12)) self.label_2.setObjectName("label_2") self.label_3 = QtWidgets.QLabel(Form) self.label_3.setGeometry(QtCore.QRect(110, 110, 54, 12)) self.label_3.setObjectName("label_3") self.pushButton = QtWidgets.QPushButton(Form) self.pushButton.setGeometry(QtCore.QRect(440, 70, 75, 23)) self.pushButton.setObjectName("pushButton") self.pushButton_2 = QtWidgets.QPushButton(Form) self.pushButton_2.setGeometry(QtCore.QRect(440, 110, 75, 23)) self.pushButton_2.setObjectName("pushButton_2") self.pushButton_2.clicked.connect(self.tz) self.retranslateUi(Form) QtCore.QMetaObject.connectSlotsByName(Form) def retranslateUi(self, Form): _translate = QtCore.QCoreApplication.translate Form.setWindowTitle(_translate("Form", "Form")) self.label.setText(_translate("Form", "温度:xxx")) self.label_2.setText(_translate("Form", "湿度:xxx")) self.label_3.setText(_translate("Form", "光照:xxx")) self.pushButton.setText(_translate("Form", "控制LED1")) self.pushButton_2.setText(_translate("Form", "历史记录")) def tz(self): self.test.show() def back(self): self.test.hide() self.show() if __name__ == '__main__': app = QtWidgets.QApplication(sys.argv) w = Ui_Form() main = QtWidgets.QMainWindow() w.setupUi(main) main.show() app.exec_()
这是一个使用PyQt5开发的UI界面代码,其中包含了多个控件,包括QLabel、QPushButton等,以及它们的位置、大小、名称等属性。其中,通过点击按钮可以实现打开一个名为ui的界面,具体实现可以在ui.py文件中查看。此外,这段代码中还包含了一些信号和槽函数的连接,以及一些基本的界面设置,如窗口大小、标题等。
阅读全文