摘要:如果编辑了按钮那么接下来就是通过按钮触发某个动作首先右击窗体生成对话框代码绑定按钮接着在代码栏就会看到生成的文件在中创建绑定再次编译打开文件发现已经绑定服务日志运行中播放暂停退出实时日志服务器开始服务密码退出状态信息类
如果编辑了按钮, 那么接下来就是通过按钮触发某个动作
首先右击窗体,生成对话框代码
绑定按钮
接着在代码栏就会看到生成的py文件
在qt designer中创建slot 绑定
再次编译 打开py文件发现已经绑定
code ui_0726.py
# -*- coding: utf-8 -*- # Form implementation generated from reading ui file "D:pythonPyQt5 726 726.ui" # # Created by: PyQt5 UI code generator 5.10.1 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(531, 648) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap("C:/Users/aabgiilln/Desktop/服务日志.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) MainWindow.setWindowIcon(icon) self.centralWidget = QtWidgets.QWidget(MainWindow) self.centralWidget.setObjectName("centralWidget") self.gridLayout = QtWidgets.QGridLayout(self.centralWidget) self.gridLayout.setObjectName("gridLayout") self.label = QtWidgets.QLabel(self.centralWidget) self.label.setObjectName("label") self.gridLayout.addWidget(self.label, 0, 0, 1, 1) self.lineEdit = QtWidgets.QLineEdit(self.centralWidget) self.lineEdit.setObjectName("lineEdit") self.gridLayout.addWidget(self.lineEdit, 0, 1, 1, 1) self.pushButton_2 = QtWidgets.QPushButton(self.centralWidget) self.pushButton_2.setObjectName("pushButton_2") self.gridLayout.addWidget(self.pushButton_2, 0, 2, 1, 1) self.label_2 = QtWidgets.QLabel(self.centralWidget) self.label_2.setObjectName("label_2") self.gridLayout.addWidget(self.label_2, 1, 0, 1, 1) self.lineEdit_2 = QtWidgets.QLineEdit(self.centralWidget) self.lineEdit_2.setObjectName("lineEdit_2") self.gridLayout.addWidget(self.lineEdit_2, 1, 1, 1, 1) self.pushButton = QtWidgets.QPushButton(self.centralWidget) self.pushButton.setObjectName("pushButton") self.gridLayout.addWidget(self.pushButton, 1, 2, 1, 1) self.textEdit = QtWidgets.QTextEdit(self.centralWidget) self.textEdit.setObjectName("textEdit") self.gridLayout.addWidget(self.textEdit, 3, 0, 1, 3) self.lineEdit_3 = QtWidgets.QLineEdit(self.centralWidget) self.lineEdit_3.setObjectName("lineEdit_3") self.gridLayout.addWidget(self.lineEdit_3, 2, 1, 1, 2) self.label_3 = QtWidgets.QLabel(self.centralWidget) self.label_3.setObjectName("label_3") self.gridLayout.addWidget(self.label_3, 2, 0, 1, 1) MainWindow.setCentralWidget(self.centralWidget) self.toolBar = QtWidgets.QToolBar(MainWindow) self.toolBar.setObjectName("toolBar") MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar) self.actionRun = QtWidgets.QAction(MainWindow) icon1 = QtGui.QIcon() icon1.addPixmap(QtGui.QPixmap("C:/Users/aabgiilln/Desktop/运行中.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.actionRun.setIcon(icon1) self.actionRun.setObjectName("actionRun") self.actionPause = QtWidgets.QAction(MainWindow) icon2 = QtGui.QIcon() icon2.addPixmap(QtGui.QPixmap("C:/Users/aabgiilln/Desktop/播放-暂停.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.actionPause.setIcon(icon2) self.actionPause.setObjectName("actionPause") self.actionQuit = QtWidgets.QAction(MainWindow) icon3 = QtGui.QIcon() icon3.addPixmap(QtGui.QPixmap("C:/Users/aabgiilln/Desktop/退出 (1).png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.actionQuit.setIcon(icon3) self.actionQuit.setObjectName("actionQuit") self.toolBar.addAction(self.actionRun) self.toolBar.addAction(self.actionPause) self.toolBar.addAction(self.actionQuit) self.retranslateUi(MainWindow) self.pushButton.clicked.connect(MainWindow.close) self.pushButton_2.clicked.connect(MainWindow.on_pushButton_clicked) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "实时日志")) self.label.setText(_translate("MainWindow", "服务器IP")) self.pushButton_2.setText(_translate("MainWindow", "开始")) self.label_2.setText(_translate("MainWindow", "服务密码")) self.pushButton.setText(_translate("MainWindow", "退出")) self.label_3.setText(_translate("MainWindow", "状态信息")) self.toolBar.setWindowTitle(_translate("MainWindow", "toolBar")) self.actionRun.setText(_translate("MainWindow", "Run")) self.actionPause.setText(_translate("MainWindow", "Pause")) self.actionQuit.setText(_translate("MainWindow", "Quit")) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) MainWindow = QtWidgets.QMainWindow() ui = Ui_MainWindow() ui.setupUi(MainWindow) MainWindow.show() sys.exit(app.exec_())
code start.py
# -*- coding: utf-8 -*- """ Module implementing Start. """ from PyQt5.QtCore import pyqtSlot from PyQt5.QtWidgets import QMainWindow from Ui_0726 import Ui_MainWindow class Start(QMainWindow, Ui_MainWindow): """ Class documentation goes here. """ def __init__(self, parent=None): """ Constructor @param parent reference to the parent widget @type QWidget """ super(Start, self).__init__(parent) self.setupUi(self) @pyqtSlot() def on_pushButton_clicked(self): """ Slot documentation goes here. """ # TODO: not implemented yet self.lineEdit_3.setText("start") if __name__ == "__main__": import sys from PyQt5.QtWidgets import QApplication app = QApplication(sys.argv) window = Start() ## 类名,注意要和自己定义的类名一致。 window.show() sys.exit(app.exec_())
result
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/42086.html
摘要:实时追加显示定义一个发送的信号通过类成员对象定义信号处理业务逻辑下面将输出重定向到中实时显示开始创建线程连接信号开始线程将当前时间输出到文本框目前遇到的问题是使用上遇到很多坑像是菜单工具栏各个按钮之间怎么去绑定特定的槽各种报错然后现在想 实时追加显示 code from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.QtCore ...
摘要:实时在文本框显示内容引入这个函数绑定定时器自动执行在类中定义一个定时器并在构造函数中设置启动及其信号和槽设置计时间隔并启动计时结束调用方法注意不要加引入这个参考 qt designer使用 开始 新建项目(eric6 项目) 新建窗体(eric6 窗体) 编辑界面(转到qt designer) 保存 编译窗体(转到eric6 窗体) 运行(查看页面效果) 页面缩放效果(qt d...
摘要:最近想做一个实用的图形界面用于查看实时日志本来是准备用开发原本以为功能简单应该很好上手然而在尝试了几次之后彻底放弃了这个想法首先太老了看上去像是上个世纪的应用界面丑陋这是其一如果只是这样还可以接受然而实际编写过程中发现也不是那么友好优质文档 最近想做一个实用的图形界面用于查看实时日志,本来是准备用tkinter开发,原本以为功能简单应该很好上手,然而,在尝试了几次之后,彻底放弃了这个想...
阅读 981·2021-11-23 09:51
阅读 2694·2021-08-23 09:44
阅读 654·2019-08-30 15:54
阅读 1431·2019-08-30 13:53
阅读 3100·2019-08-29 16:54
阅读 2526·2019-08-29 16:26
阅读 1185·2019-08-29 13:04
阅读 2313·2019-08-26 13:50