https://blog.youkuaiyun.com/qq_36711094/article/details/110474759
这是上一篇日志拉取小工具的文章
之前使用的是win的cmd窗口操作,这次使用qt5构建界面,增强了可移植性,还是话不多说,直接上代码,注释不清晰的,可以私信作者
本文是在大佬示例代码基础上修改的,送上大佬主页
https://blog.youkuaiyun.com/seniorwizard
另,老生常谈,******可以自由替换
主页面py文件
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'Form.ui'
#
# Created by: PyQt5 UI code generator 5.10.1
#
# WARNING! All changes made in this file will be lost!
#要注意的是跳转界面第二个必须使用QDialog类,不能使用QWidget,我也不知道为什么,特别注意
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import (QMainWindow, QApplication,QLabel,QLineEdit,QMessageBox,QComboBox)
from PyQt5.QtCore import Qt, QSize
import Dialog1
import Dialog2
import sys
class Ui_Form(object): #这是用PyQt Designer生成的代码,很简单的,拖动控件,生成ui文件,然后UIC转换成py文件
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(440, 310)
self.form = Form
self.btn_d1 = QtWidgets.QPushButton(Form)
self.btn_d1.setGeometry(QtCore.QRect(60, 240, 75, 23))
self.btn_d1.setObjectName("btn_d1")
self.btn_d2 = QtWidgets.QPushButton(Form)
self.btn_d2.setGeometry(QtCore.QRect(180, 240, 75, 23))
self.btn_d2.setObjectName("btn_d2")
self.btn_exit = QtWidgets.QPushButton(Form)
self.btn_exit.setGeometry(QtCore.QRect(300, 240, 75, 23))
self.btn_exit.setObjectName("btn_exit")
#用户名lab
self.label_username = QtWidgets.QLabel(Form)
self.label_username.setGeometry(QtCore.QRect(60, 60, 75, 23))
self.label_username.setObjectName("label_username")
#密码lab
self.label_password = QtWidgets.QLabel(Form)
self.label_password.setGeometry(QtCore.QRect(60, 100, 75, 23))
self.label_password.setObjectName("label_username")
# 用户名edit
self.le_username = QtWidgets.QLineEdit(Form)
self.le_username.setGeometry(QtCore.QRect(140, 60, 180, 23))
self.le_username.setObjectName("le_username")
# 密码edit
self.le_password = QtWidgets.QLineEdit(Form)
self.le_password.setEchoMode(QLineEdit.Password) # 输入显示为圆点
self.le_password.setGeometry(QtCore.QRect(140, 100, 180, 23))
self.le_password.setObjectName("le_username")
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "登录"))
self.btn_d1.setText(_translate("Form", "历史连接"))
self.btn_d1.clicked.connect(self.jump_to_demo1)
self.btn_d2.setText(_translate("Form", "新建连接"))
self.btn_d2.clicked.connect(self.jump_to_demo2)
self.btn_exit.setText(_translate("Form", "退出"))
self.btn_exit.clicked.connect(self.exit)
self.label_username.setText(_translate("Form", "用户名"))
self.label_password.setText(_translate("Form", "密码"))
self.le_username.setPlaceholderText("请输入用户名")
self.le_password.setPlaceholderText("请输入密码")
def jump_to_demo1(self):
#测试逻辑代码
if self.le_username.text() != "1":
#self.le_username很重要,不加.le_username会报错,寻不到默认self
QtWidgets.QMessageBox.information(self.le_username, "提示信息", "用户名错误")
elif self.le_password.text() != "1":
QMes